How is jms session handled in a flow containing in

2019-05-20 13:16发布

I have the following flow:

   1) message-driven-channel-adapter -> 
             1.1) output-channel connected to -> service-activator -> outbound-channel-adapter (for sending response)
             1.2) error-channel connected to -> exception-type-router 
                        1.2.1) message is sent to different queues depending on the exception type using outbound-channel-adapter

         MessageDrivenChannelAdapter uses DefaultMessageListenrContainer and OutboundAdapter uses JMSTemplate
         Have used same cachingconnectionfactory for inbound and outbound adapters, 
         set acknowledge="transacted" in messageDrivenChannelAdapter
         set cacheLevel as CACHE_CONSUMER in DefaultMessageListenerContainer
         set cacheProducers=true and cacheConsumers=false in CachingConnectionFactory

I am so confused as how jms session/producer/consumer is created and handled in this flow.

1) whether the consumers and producers used by inbound adapter, outbound adapters(used for response and the error queues) are created from the same session i.e. whether producers and consumers used in a thread are created from the same session?

2) And Just wanted to confirm as whether there are any disadvantage/issues in using cachingconnectionfactory even after setting 1)cacheConsmers to false in the factory and 2)cache level to CACHE_CONSUMER at the DefaultMessageListenerContainer. Because , it is confusing to read the forums saying that cachingconnectionfactory should not be used.

3)Also , have a doubt on the execution flow: In the flow, when will the service activator method execution complete ? Will it complete only after the message is sent to the output queue?

Please advise

1条回答
我命由我不由天
2楼-- · 2019-05-20 13:32
  1. It's ok to use a caching connection factory with the listener container, as long as you don't use variable concurrency, or you disable caching consumers in the factory.
  2. In your scenario, you should use a caching connection factory because you really want the producers to be cached for performance reasons.

When the container acknowledgemode is transacted, the container session is bound to the thread and will be used by any upstream JmsTemplate that is configured to use the same connection factory, as long as there is no asynch handoff (QueueChannel or ExecutorChannel); the default DirectChannel runs the downstream endpoints on the container thread.

The service activator method is invoked (and "completes") before sending the message to the outbound adapter.

查看更多
登录 后发表回答