configuring DefaultMessageListenerContainer as topic and testing it with client
Hello,
I followed an example to configure DefaultMessageListenerContainer at server side as follow:
lt;bean id=quot;containerquot; class=quot;org..jms.listener.DefaultMes sageListenerContainerquot;gt; lt;property name=quot;connectionFactoryquot; ref=quot;jmsConnectionFactoryquot;/gt; lt;property name=quot;messageListenerquot; ref=quot;helloListenerquot;/gt; lt;property name=quot;destinationquot; ref=quot;requestTopicquot;/gt; lt;/beangt;I am not sure how on client side I can configure the following so that I can put my message with destination as quot;topicquot; instead of a quot;queuequot;lt;bean id=quot;helloClientServicequot; class=quot;org..jms.remoting.JmsInvoker ProxyFactoryBeanquot;gt; lt;property name=quot;connectionFactoryquot; ref=quot;jmsConnectionFactoryquot;/gt; lt;property name=quot;queuequot; ref=quot;requestQueuequot;/gt; lt;property name=quot;serviceInterfacequot; value=quot;com.test.HelloServicequot;/gt; lt;/beangt;
In this above client configuration, it seems that JmsInvokerProxyFactoryBean only has a property for quot;queuequot; - how can I have the client configured for a topic to use quot;requestTopicquot; instead of quot;requestQueuequot;?
thanks.
The JmsInvokerProxyFactoryBean is intended for RPC using JMS as the underlying transport, where you've explicitly exported a service for remoting, as described here:
docs/...l#remoting-jms
It is not intended for use as a general JMS client, which is why it does not provide an option to configure a topic. For that, you can use the JmsTemplate class:
docs/...ms-jmstemplate
mand.ActiveMQTopicquot;gt; lt;constructor-arg value=quot;outTopicquot;/gt; lt;/beangt;
lt;bean id=quot;jmsTemplatequot; class=quot;org..jms.core.JmsTemplatequot;gt; lt;property name=quot;connectionFactoryquot; ref=quot;jmsConnectionFactoryquot; /gt; lt;property name=quot;defaultDestinationNamequot; value=quot;outTopicquot; /gt; lt;property name=quot;pubSubDomainquot; value=quot;truequot; /gt; lt;/beangt;
lt;bean id=quot;jmsSenderquot; class=quot;com.test.MyJmsSenderquot;gt; lt;property name=quot;jmsTemplatequot; ref=quot;jmsTemplatequot; /gt; lt;/beangt;
This doesn't store the message in my activemq database. However, if I change pubSubDomain to quot;falsequot;, it stores the message as a queue--outTopic in my activemq database. What do I need to do to have this as topic and still persist in database? My usecase is that I need to publish all these messages to a topic and let the other client systems use this published messages outside my application.
mand.ActiveMQTopicquot;gt; lt;constructor-arg value=quot;outTopicquot;/gt; lt;/beangt;
lt;bean id=quot;jmsTemplatequot; class=quot;org..jms.core.JmsTemplatequot;gt; lt;property name=quot;connectionFactoryquot; ref=quot;jmsConnectionFactoryquot; /gt; lt;property name=quot;defaultDestinationNamequot; value=quot;outTopicquot; /gt; lt;property name=quot;pubSubDomainquot; value=quot;truequot; /gt; lt;/beangt;
lt;bean id=quot;jmsSenderquot; class=quot;com.test.MyJmsSenderquot;gt; lt;property name=quot;jmsTemplatequot; ref=quot;jmsTemplatequot; /gt; lt;/beangt;This doesn't store the message in my activemq database. However, if I change pubSubDomain to quot;falsequot;, it stores the message as a queue--outTopic in my activemq database. What do I need to do to have this as topic and still persist in database? My usecase is that I need to publish all these messages to a topic and let the other client systems use this published messages outside my application.
Please help.
Hi User2,
I guess we are both struggling with the same issue.
Here is my understanding why it is happening to me so far.
A topic (without durable subscribers) will only store a message when there is a consumer subscribed. So if you send the message while no consumer is subscribed yet, you will never receive it, but it will be discarded by the broker.
Now template conveniently hides the connection and consumer subscriptions from the client, so I don't know which call does trigger the subscription and how to actually stay subscribed.
I'll study this a bit more and share my solution here.
K
Hi User2,
here is what I didCode:
tcf = (TopicConnectionFactory) template.getConnectionFactory();
tc = tcf.createTopicConnection();
s = tc.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = s.createConsumer(template.getDefaultDestination());
tc.start();
This is needed in some sort of initialization code and you can then call
Code:
consumer.receive();
I hope that gives you a path to work with. It is not elegant, as it uses the template as a bean property container only, but it apparently works (for me).
Good luck |