-
1. Re: Embedded HornetQ and Topics
clebert.suconic Nov 18, 2009 4:58 PM (in response to levidean)Do you have some code showing what you're trying to achieve?
-
2. Re: Embedded HornetQ and Topics
levidean Nov 18, 2009 5:16 PM (in response to levidean)Basicaly what I am trying to do is upgrade some existing code that used JMS and a JBoss server to use embedded HornetQ instead.
I get the exception at the session.createSubscriber line.public void setTopicSubscriber(String topicName, MessageListener subscriber, String selector, boolean noLocal) { topicName = topicPrefix + topicName; //topicName = topicPrefixName + topicName; try { HornetQSession session = sessions.get(topicName); Topic topic = (HornetQTopic) destinations.get(topicName); /** * Create a subscriber to the topic, using the message selector. The third parameter is set to true which inhibits the delivery of messages published by its own connection */ TopicSubscriber topicSubscriber = session.createSubscriber(topic, selector, noLocal); TopicConnection topicConnection = (TopicConnection) connections.get(topicName); topicSubscriber.setMessageListener(subscriber); topicConnection.start(); } catch (javax.jms.InvalidDestinationException e){ e.printStackTrace(); } catch (javax.jms.JMSException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
The following is the highlights of setting up the topics and queues.connectionFactory = new HornetQConnectionFactory(new TransportConfiguration(InVMConnectorFactory.class.getName())); connection = (HornetQConnection) connectionFactory.createConnection(); session = (HornetQSession) connection.createSession(transacted, ackMode); if (destinationName.contains("topic")) { destination = (HornetQDestination) new HornetQTopic(env.get(destinationName)); } else if (destinationName.contains("queue")) { destination = (HornetQDestination) new HornetQQueue(env.get(destinationName)); } producer = (HornetQMessageProducer) session.createProducer(destination); connections.put(destinationName, connection); destinations.put(destinationName, destination); messageProducers.put(destinationName,producer); sessions.put(destinationName,session);
Where connections, destinations, messageProducers and sessions are hashtables. -
3. Re: Embedded HornetQ and Topics
jmesnil Nov 19, 2009 3:31 AM (in response to levidean)how do you configure your topics?
have you looked at the example jms/topic? -
4. Re: Embedded HornetQ and Topics
levidean Nov 19, 2009 12:00 PM (in response to levidean)I have looked at most of the examples. I'm trying to embed it so I've been following example jms/embedded. I'm not having trouble with queues, just topics.
What do you mean how am I configuring my topics?
I'm directly instantiating them.destination = (HornetQDestination) new HornetQTopic(topicName);
-
5. Re: Embedded HornetQ and Topics
ataylor Nov 19, 2009 2:11 PM (in response to levidean)The code you are showing is just client code. You need to configure/create the destinations on the server. There are a few ways to do this, either via the configuration file or programatically via a JMSServermanager Object. take a look at the EmbeddedExample.
-
6. Re: Embedded HornetQ and Topics
levidean Nov 19, 2009 2:35 PM (in response to levidean)Do you mean step 4 of the Embedded Example?
That uses the Core API, I'm trying to use the JMS API.
http://hornetq.sourceforge.net/docs/hornetq-2.0.0.BETA5/user-manual/en/html/embedding-hornetq.html
Also I don't see any JMSServerManager objects in the Embedded Example to take a look at. The Core API works fine for queues, but I can't find any support for topics.
Are they any examples of how to correctly use a JMSServerManager object? -
7. Re: Embedded HornetQ and Topics
ataylor Nov 19, 2009 3:30 PM (in response to levidean)take a look at step 8.
// Step 8. Start the JMS Server using the HornetQ core server and the JMS configuration JMSServerManager jmsServer = new JMSServerManagerImpl(hornetqServer, jmsConfig); jmsServer.start();
and thenjmsServer.createTopic("myTopic", "topic/myTopic");
In the core API there is no concept of queue thats why you cant find anything. Read the section in the manual about addresses and queues to see how topics work. -
8. Re: Embedded HornetQ and Topics
levidean Nov 19, 2009 4:45 PM (in response to levidean)Okay, I'm getting you now. I see why I couldn't find what I was looking for.
I can't find the EmbededExample you are talking about. Is it the one in the file path: examples\jms\embedded?
Step 8 of the copy I have is:// Step 8. Receive the message. TextMessage messageReceived = (TextMessage)messageConsumer.receive(1000); System.out.println("Received TextMessage:" + messageReceived.getText());
-
9. Re: Embedded HornetQ and Topics
ataylor Nov 20, 2009 3:13 AM (in response to levidean)The example has probably changed, take a look at http://anonsvn.jboss.org/repos/hornetq/trunk/examples/jms/embedded/src/org/hornetq/jms/example/EmbeddedExample.java
-
10. Re: Embedded HornetQ and Topics
levidean Nov 20, 2009 1:04 PM (in response to levidean)Ataylor, Thanks for all your help. That example helps a bunch.
But I've got a new problem. The HornetQ libraries I have are deficient. The hornetq-jms.jar I have doesn't have the path for the imports:import org.hornetq.jms.server.config.ConnectionFactoryConfiguration; import org.hornetq.jms.server.config.JMSConfiguration; import org.hornetq.jms.server.config.QueueConfiguration; import org.hornetq.jms.server.config.impl.ConnectionFactoryConfigurationImpl; import org.hornetq.jms.server.config.impl.JMSConfigurationImpl; import org.hornetq.jms.server.config.impl.QueueConfigurationImpl;
Under server these isn't a config folder. Is there some where I can get this library. -
11. Re: Embedded HornetQ and Topics
jmesnil Nov 20, 2009 1:12 PM (in response to levidean)"levidean" wrote:
Under server these isn't a config folder. Is there some where I can get this library.
from the trunk.
But you don't need these classes.
If you are using HornetQ 2.0.0.Beta5, create a JMSServerManagerImpl and use the createTopic() method to create and deploy the JMS topic on the server