-
1. Re: Is there a ClientSubscriber like a ClientConsumer?
gaohoward Nov 30, 2011 10:01 PM (in response to fastbucks)With HornetQ you just need the same ClientConsumer for topics. In HornetQ core there isn't a concept of 'topics'. To achieve a 'topic' you just need to create multiple queues bound to one same address.
Howard
-
2. Re: Is there a ClientSubscriber like a ClientConsumer?
fastbucks Dec 1, 2011 12:34 PM (in response to gaohoward)I am using JMS components within HornetQ. So, I am not sure how the suggested solution would work. Can you please elaborate? Thanks.
-
3. Re: Is there a ClientSubscriber like a ClientConsumer?
clebert.suconic Dec 1, 2011 5:27 PM (in response to fastbucks)I didn't get what's your question.. if you are using JMS ,you can just use MessageListener within a Durable subscription:
Session sess = ...;
TopicSubscriber x = sess.createDurableSubscriber(null,null);
x.setMessageListener(listener)
-
4. Re: Is there a ClientSubscriber like a ClientConsumer?
fastbucks Dec 1, 2011 10:06 PM (in response to clebert.suconic)Based on your suggestion, I created the following sample. It is getting registered but the onMessage method is not getting called when a message is published on the topic. Anything I am missing here?
import java.util.HashMap;
import java.util.Map;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Session;
import javax.jms.TopicSubscriber;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.jms.HornetQJMSClient;
import org.hornetq.api.jms.JMSFactoryType;
import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory;
import org.hornetq.jms.client.HornetQConnectionFactory;
public class MyMessageHandler implements MessageListener {
public MyMessageHandler() {
registerHandler();
}
private void registerHandler() {
System.out.println("hey registering the handler");
Map<String, Object> map = new HashMap<String, Object>();
map.put("host", "localhost");
map.put("port", 5445);
TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), map);
HornetQConnectionFactory connectionFactory = HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF,
transportConfiguration);
try {
Connection jmsConnection = connectionFactory.createConnection("fun", "fun");
jmsConnection.setClientID("1000");
Session session = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber topicSubscriber = session.createDurableSubscriber(
HornetQJMSClient.createTopic("test"), "test");
topicSubscriber.setMessageListener(this);
System.out.println("registered the handler");
} catch (JMSException e) {
e.printStackTrace();
}
}
@Override
public void onMessage(Message message) {
System.out.println("hey got the message");
}
}
I am getting it registered by having it configured as a bean in hornetq-beans.xml.
<bean name="MyMessageHandler" class="MyMessageHandler">
<start ignored="false"/>
<stop ignored="false"/>
<depends>JMSServerManager</depends>
</bean>
-
5. Re: Is there a ClientSubscriber like a ClientConsumer?
ataylor Dec 2, 2011 3:41 AM (in response to fastbucks)1 of 1 people found this helpfulyou need to start your connection to receive messages, i would recommend reading a JMS tutorial, the Sun one is pretty good
-
6. Re: Is there a ClientSubscriber like a ClientConsumer?
fastbucks Dec 2, 2011 2:15 PM (in response to ataylor)Duh. Just needed an extra pair of eyes I guess working late in the day. Missed that simple obvious one.