-
1. Re: Embedding HornetQ?
tfennelly Aug 24, 2009 6:42 AM (in response to tfennelly)Oops.... sorry for the "MornetQ" typo there :)
-
2. Re: Embedding HornetQ?
jmesnil Aug 24, 2009 6:45 AM (in response to tfennelly)"tfennelly" wrote:
Hey guys.... I see in the FAQ that HornetQ is embeddable. Is there anything in the docs wrt this? I couldn't see it if there was. When ye get a chance, could someone add it please?
http://hornetq.sourceforge.net/docs/hornetq-2.0.0.BETA5/user-manual/en/html/embedding-hornetq.html"tfennelly" wrote:
2. Sample code for embedding e.g. a JUnit test example where MornetQ is used as JMS provider in the test.
have a look at the examples/jms/embedded in the distribution -
3. Re: Embedding HornetQ?
jmesnil Aug 24, 2009 6:56 AM (in response to tfennelly)"tfennelly" wrote:
1. Maven Dependencies required for embedding.
HornetQ does not use Maven for build but we provide a POM so that you can fetch our deps:
http://anonsvn.jboss.org/repos/hornetq/tags/HornetQ_2_0_0_Beta5/pom.xml
I'll add info for maven to the download page http://jboss.org/hornetq/downloads.html today. -
4. Re: Embedding HornetQ?
tfennelly Aug 24, 2009 6:59 AM (in response to tfennelly)Thanks Jeff... I was looking for it in the Quick Start Guide... sorry!!!
Might be worth adding the maven dependencies to the user guide at the location you linked above. Would be nice to not have to download the distro in order to use it for this purpose (an embedded JMS Provider for testing). -
5. Re: Embedding HornetQ?
ataylor Aug 24, 2009 7:03 AM (in response to tfennelly)I'll get the jars uploaded to Maven soon and add some links, docs etc.
-
6. Re: Embedding HornetQ?
jmesnil Aug 24, 2009 7:06 AM (in response to tfennelly)"tfennelly" wrote:
Thanks Jeff... I was looking for it in the Quick Start Guide... sorry!!!
Might be worth adding the maven dependencies to the user guide at the location you linked above. Would be nice to not have to download the distro in order to use it for this purpose (an embedded JMS Provider for testing).
Good idea, I'll add the maven info to the quick start guide. -
7. Re: Embedding HornetQ?
gregory.mostizky1 Aug 25, 2009 8:29 AM (in response to tfennelly)I was able to run embedded example (core/embedded) using this short maven snippet:
<repositories> <repository> <id>jboss</id> <url>http://repository.jboss.com/maven2/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <dependencies> <dependency> <groupId>org.hornetq</groupId> <artifactId>hornetq-core</artifactId> <version>2.0.0.BETA5</version> </dependency> </dependencies>
-
8. Re: Embedding HornetQ?
ataylor Aug 25, 2009 9:00 AM (in response to tfennelly)The rest of the libs will be up there soon and i'll also post a full maven example
-
9. Re: Embedding HornetQ?
clindevall Aug 27, 2009 12:49 PM (in response to tfennelly)Is it possible to create JMS topics as easily as queues in HornetQ?
The embedded queue example is simple enough (with or without JNDI), but I couldn't find a similar example for topics.
I managed to dynamically create a JMS topic, but this sample requires a JNDI service and seems a bit cumbersome (especially step 1e):public void testJmsTopic() throws Exception { Connection connection = null; InitialContext initialContext = null; try { //Step 1a. Create an initial context to perform the JNDI lookup. initialContext = new InitialContext(); //Step 1b. Manually bind the connection factory to JNDI HornetQConnectionFactory hcf = new HornetQConnectionFactory(new TransportConfiguration(InVMConnectorFactory.class.getName())); initialContext.bind("myConnectionFactory", hcf); //Step 1c. Create the Configuration, and set the properties accordingly Configuration configuration = new ConfigurationImpl(); configuration.setPersistenceEnabled(false); configuration.setSecurityEnabled(false); configuration.getAcceptorConfigurations().add( new TransportConfiguration(InVMAcceptorFactory.class.getName())); //Step 1d. Create and start the server HornetQServer server = HornetQ.newHornetQServer(configuration); server.start(); //Step 1e. Create and start the JMS service (also create a topic and bind it to JNDI) JMSServerManagerImpl mgr = new JMSServerManagerImpl(server); mgr.start(); mgr.activated(); mgr.createTopic("ServiceLocator", "myTopic"); //Step 2. perform a lookup on the topic Topic topic = (Topic) initialContext.lookup("myTopic"); //Step 3. perform a lookup on the Connection Factory ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("myConnectionFactory"); //Step 4. Create a JMS Connection connection = cf.createConnection(); //Step 5. Create a JMS Session Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); //Step 6. Create a Message Producer MessageProducer producer = session.createProducer(topic); //Step 7. Create a JMS Message Consumer MessageConsumer messageConsumer1 = session.createConsumer(topic); //Step 8. Create a JMS Message Consumer MessageConsumer messageConsumer2 = session.createConsumer(topic); //Step 9. Create a Text Message TextMessage message = session.createTextMessage("This is a text message"); System.out.println("Sent message: " + message.getText()); //Step 10. Send the Message producer.send(message); //Step 11. Start the Connection connection.start(); //Step 12. Receive the message TextMessage messageReceived = (TextMessage) messageConsumer1.receive(); System.out.println("Consumer 1 Received message: " + messageReceived.getText()); //Step 13. Receive the message messageReceived = (TextMessage) messageConsumer2.receive(); System.out.println("Consumer 2 Received message: " + messageReceived.getText()); // return true; } finally { //Step 14. Be sure to close our JMS resources! if (connection != null) { connection.close(); } // Also the initialContext if (initialContext != null) { initialContext.close(); } } }
-
10. Re: Embedding HornetQ?
leosbitto Aug 27, 2009 3:52 PM (in response to tfennelly)"c2lindevall" wrote:
Is it possible to create JMS topics as easily as queues in HornetQ?
The embedded queue example is simple enough (with or without JNDI), but I couldn't find a similar example for topics.
Check http://www.jboss.org/index.html?module=bb&op=viewtopic&t=157803 to see how I did create topics with an embedded server, after Andy Taylor navigated me to JMSServerManagerImpl. -
11. Re: Embedding HornetQ?
clindevall Aug 29, 2009 6:13 AM (in response to tfennelly)Thx for the pointer:
Check http://www.jboss.org/index.html?module=bb&op=viewtopic&t=157803 to see how I did create topics with an embedded server, after Andy Taylor navigated me to JMSServerManagerImpl.
I was looking at the JMSServerManagerImpl earlier and realized that it does the JNDI binding for you. I opted to use the JMSServerManagerImpl (and its JNDI binding) in the hopes that it will be safer than "hard coding" the REJECT_FILTER "__HQX=-1" in my own "createTopicWithoutJNDIBinding"-method.
Anyways, HornetQ is awesome and I like it's clean-cut design and lack of dependencies to two thousand other libraries.. Hopefully JBossOSGi will include it soon.. :)