Feeds

Programming message services in Java

Asynchronous interactions seem to be the way of the future

Secure remote control for conventional and virtual desktops

Publish destinations

How a destination is published is message service dependent. In the case of the JBossMQ message server a destination can be published by providing an entry in the JBossmq-destinations-service.xml file (found under the \server\default\deploy\jms directory for the default Jboss server configuration). By default a number of queues are already defined and we will use one of these, the queue/testQueue. By contrast, in WebLogic and WebSphere queues can be defined using the application server consoles.

The entry for the JBossmq-destinations-service.xml file for the queue/testQueue is presented below:

  <mbean code="org.jboss.mq.server.jmx.Queue"
         name="jboss.mq.destination:service=Queue,name=testQueue">
    <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
    <depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>
    <attribute name="MessageCounterHistoryDayLimit">-1</attribute>
    <attribute name="SecurityConf">
      <security>
        <role name="guest" read="true" write="true"/>
        <role name="publisher" read="true" write="true" create="false"/>
        <role name="noacc" read="false" write="false" create="false"/>
      </security>
    </attribute>
  </mbean>

Define a client

To send a message to a JMS message server queue, there are a number of steps that must be performed. These steps are the same whether you wish to send the message from a stand-alone application, from a Servlet or JSP, or indeed from an Enterprise JavaBean. These steps are:

Step 1: Obtain a queue connection factory. A queue connection factory is used to create the queue connection object used to handle the connection to the message servers’ queue.

Step 2: Create a queue connection. This is done by calling the createQueueConnection method on the factory object just obtained.

Step 3: Create a queue session. A queue session is obtained from the queue connection, as illustrated below:

QueueSession qs = 
             qc.createQueueSession(false, 
             Session.AUTO_ACKNOWLEDGE);

The first argument to the createQueueSession method above indicates that this is not part of a transaction. The second argument indicates that the queue session automatically acknowledges messages when they have been received successfully. Until a JMS message has been acknowledged, it is not considered to be successfully consumed.

Step 4: Look up the queue. This is done by using the initial context object we created earlier and looking up the queue using its JNDI name (e.g. queue/testQueue).

Step 5: Create a queue sender. A queue sender is a message producer that allows messages to be sent to the specified queue. A queue sender is created using the createSender method on the queue session:

Step 6: Create the message object.

Step 7: Send the message via the QueueSender object created in step 5.

Step 8: Close the queue connection.

The essential guide to IT transformation

More from The Register

next story
The Return of BSOD: Does ANYONE trust Microsoft patches?
Sysadmins, you're either fighting fires or seen as incompetents now
China hopes home-grown OS will oust Microsoft
Doesn't much like Apple or Google, either
Microsoft refuses to nip 'Windows 9' unzip lip slip
Look at the shiny Windows 8.1, why can't you people talk about 8.1, sobs an exec somewhere
This is how I set about making a fortune with my own startup
Would you leave your well-paid job to chase your dream?
Microsoft cries UNINSTALL in the wake of Blue Screens of Death™
Cache crash causes contained choloric calamity
Eat up Martha! Microsoft slings handwriting recog into OneNote on Android
Freehand input on non-Windows kit for the first time
Linux kernel devs made to finger their dongles before contributing code
Two-factor auth enabled for Kernel.org repositories
prev story

Whitepapers

Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
5 things you didn’t know about cloud backup
IT departments are embracing cloud backup, but there’s a lot you need to know before choosing a service provider. Learn all the critical things you need to know.
Why and how to choose the right cloud vendor
The benefits of cloud-based storage in your processes. Eliminate onsite, disk-based backup and archiving in favor of cloud-based data protection.
Top 8 considerations to enable and simplify mobility
In this whitepaper learn how to successfully add mobile capabilities simply and cost effectively.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?