Enterprise Java

JBoss HornetQ for Kids, Parents and Grandparents – Chapter 1

It’s now almost 4 years that I’m working with HornetQ and I think it’s time to share part of what I learnt so far.

The main purpose of this post is not to rewrite the official documentation, but it’s to clarify, in simple ways, the concepts we use most here in PaddyPower .

What is HornetQ

HornetQ is a JMS implementation. JMS is a message oriented middle-ware API to exchange information between producers and consumers in an asynchronous way.

HornetQ is one of the numerous framework out there that implement the JMS API.

Configuration

All the HornetQ configuration we care about is in 1 folder. How beautiful is that?! The folder is hornetq (or hornetq.sar dipending on the jboss version you are using) and you can find it in your jboss profile deploy folder.

In this folder we have up to 7 xml configuration files. We really care only about 2:

  • hornetq-jms.xml and hornetq-configuration.xml.
  • hornetq-jms.xml

This is where you want to define your JNDI names for queues, topics and connection factories.

By default all the Connection factories, the dead letter and the expiry Queue are already configured.

What you need to add is only the queues or topics that your application needs to use.

For example:

<queue name='phaseQueueFromEngine'>
     <entry name='/queue/phaseQueueFromEngine'/>
</queue>

the entry name is the JNDI name used by your producer and consumer to discover the queue.

hornetq-configuration.xml

This is where you want to define acceptors, connectors, bridges and other cool stuff.

Understanding Connectors & Acceptors

Ok, this can be tricky, so I’ll try to be simple and essential.

HornetQ run in a server (JBoss for example) or as standalone application.

In any of the above cases, HornetQ works by communicating with his own server, the HornetQ server.

In order to communicate with it, we have to tell how we connect to and what we accept as connection.

  • Acceptors define which type of connection are accepted by the HornetQ Server.
  • Connectors define how to connect to the HornetQ server.

Luckily, only 2 kind of connectors and acceptors are possible, in-vm and netty. in-vm is used when the producer and the consumer lives in the same virtual machine.

Example:

<acceptor name='in-vm'>
        <factory-class>org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
</acceptor>
<connector name='in-vm'>
       <factory-class>org.hornetq.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
</connector>

netty is used when the producer and the consumer lives in different virtual machines.

Example:

Producer/Consumer in the same machine:

<acceptor name='netty'>
         <factory-class>org.hornetq.integration.transports.netty.NettyAcceptorFactory</factory-class>
         <param key='host'  value='${host:localhost}'/>
         <param key='port'  value='${port:5445}'/>
      </acceptor>
<connector name=”netty”>
<factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory</factory-class>
<param key=”host” value=”${host:localhost}”/>
<param key=”port” value=”${port:5445}”/>
</connector>

 
Producer/Consumer in different machines:

Consumer Box

<acceptor name=”netty-external-acceptor”>
<factory-class>org.hornetq.integration.transports.netty.NettyAcceptorFactory</factory-class>
<param key=”host” value=”172.x.x.62″/>
<param key=”port” value=”5445″/>
</acceptor>

Producer Box

<connector name='remote-engine-connector'>
         <factory-class> org.hornetq.integration.transports.netty.NettyConnectorFactory</factory-class>
         <param key='host' value='172.x.x.62'/>
         <param key='port' value='5445'/>
      </connector>

So far so good.

Pay attention when you configure acceptors and connectors because in order to communicate properly they have to be the same kind with the same host and port.

netty acceptor with netty connector (same host and port )
GOOD

in-vm acceptor with in-vm connector
GOOD

in-vm acceptor with netty connector
BAD

netty acceptor port 5445 with netty connector 5446
BAD

netty acceptor host 172.x.x.60 with netty connector 172.x.x.62
BAD

Understanding Bridges

Another feature I widely used is the bridge.

If you have a producer living in the box 172.x.x.60 and the consumer sitting in the box 172.x.x.62 you need to connect them and you do this configuring a bridge in our beloved configuration file hornetq-configuration.xml

Example :

<bridge name=”from60to62Bridge”>
<queue-name>jms.queue.phaseQueueToEngine</queue-name>
<forwarding-address>jms.queue.phaseQueueFromInput</forwarding-address>
<reconnect-attempts>-1</reconnect-attempts>
<connector-ref connector-name=”remote-engine-connector”/>
</bridge>

Yes, you use the connector to specify where to connect to the other hornetQ server. Easy!

I hope this will clarify a couple of aspects and it will help to understand better the sometime scary Hornetq configuration.

Coming soon.. HornetQ for Kids, Parents and Grandparents – Chapter 2: the magic of address-settings
 

Reference: JBoss HornetQ for Kids, Parents and Grandparents – Chapter 1 from our JCG partner Marco Castigliego at the Remove duplication and fix bad names blog.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Idan Fridman
Idan Fridman
12 years ago

Hi,

There is ambiguity in your example.

you saying in-vm is for producer and the consumer lives in the same virtual machine.

and in other hand you said that with netty the producer and the consumer lives in different virtual machines.

and then you give this example:

Producer/Consumer in the same machine:

1

2 org.hornetq.integration.transports.netty.NettyAcceptorFactory

3

4

5

view source

print?

1

2org.hornetq.integration.transports.netty.NettyConnectorFactory

3

4

5

this example includes netty configuration. and you still wrote above it: “Producer/Consumer in the same machine:”

Please clarify.

thanks.

marco
12 years ago
Reply to  Idan Fridman

Hey Idan,

You are right, there is a confusion on the following sentence “netty is used when the producer and the consumer lives in different virtual machines.”

What I should have wrote is “netty must be used when the producer and the consumer lives in different virtual machines.”

Which it means that netty can be also used on the same virtual machine, but it MUST be used on different virtual machines.

Thanks for pointing this out.

Marco

Idan Fridman
Idan Fridman
12 years ago
Reply to  marco

Thanks Marco. waiting for your next chapter:)

krishna
krishna
10 years ago

Hi i am new to hornetQ implementation,i have some doubts regarding this,can you please help me,i want to implement multiple queues ,is it possible to connect multiple queues?,if yes please give me sample example how to do this.

Thanks in advance
krishna

husna
husna
10 years ago

Hi,
Please help me in creating hornetq-jms.xml and where i have place this file in jboss6.1.please reply me to my mail id.

Back to top button