Feeds

Programming message services in Java

Asynchronous interactions seem to be the way of the future

Choosing a cloud hosting partner with confidence

At this point, the client will have sent a message to the JMS message server available within the JBoss application server.

The complete JMS client is presented below, based on the above description:

package com.regdeveloper.jms.client;

import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class NewsClient {

   public static void main(String [] args) throws Exception {
      if (args.length == 0) {
         printUsage();
      } else {
         String text = args[0];
         System.out.println("Sending Msg: " + text);
         
         Context context = new InitialContext();
         System.out.println("Got Initial Context");
         // Get connection factory from naming service
         QueueConnectionFactory f =  
                 (QueueConnectionFactory)
                            context.lookup("ConnectionFactory");
         System.out.println("Obtained queue connection factory");
         // Create the connection
         QueueConnection qc = f.createQueueConnection();
         System.out.println("Obtained the queue connection");
         // Create the session
         QueueSession qs = 
             qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
         System.out.println("Obtained the queue session");
         // Note queue must be placed before the queue name
         Queue q = (Queue)context.lookup("queue/testQueue");
         System.out.println("Obtained the queue: " +
                                q.getQueueName());
         QueueSender sender = qs.createSender(q);
         TextMessage message = qs.createTextMessage();
         message.setText(text);
         System.out.println("Sending message to queue");
         sender.send(q, message);
         System.out.println("Message sent");
         // Must close the connection
         qc.close();
      }  
   }
   public static void printUsage() {  
         System.out.println("java NewsClient <message>"); 
   }
}

Internet Security Threat Report 2014

Next page: The consumer

More from The Register

next story
PEAK APPLE: iOS 8 is least popular Cupertino mobile OS in all of HUMAN HISTORY
'Nerd release' finally staggers past 50 per cent adoption
Microsoft to bake Skype into IE, without plugins
Redmond thinks the Object Real-Time Communications API for WebRTC is ready to roll
Microsoft promises Windows 10 will mean two-factor auth for all
Sneak peek at security features Redmond's baking into new OS
Mozilla: Spidermonkey ATE Apple's JavaScriptCore, THRASHED Google V8
Moz man claims the win on rivals' own benchmarks
Yes, Virginia, there IS a W3C HTML5 standard – as of now, that is
You asked for it! You begged for it! Then you gave up! And now it's HERE!
FTDI yanks chip-bricking driver from Windows Update, vows to fight on
Next driver to battle fake chips with 'non-invasive' methods
DEATH by PowerPoint: Microsoft warns of 0-day attack hidden in slides
Might put out patch in update, might chuck it out sooner
Ubuntu 14.10 tries pulling a Steve Ballmer on cloudy offerings
Oi, Windows, centOS and openSUSE – behave, we're all friends here
prev story

Whitepapers

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.
A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
Saudi Petroleum chooses Tegile storage solution
A storage solution that addresses company growth and performance for business-critical applications of caseware archive and search along with other key operational systems.
Simplify SSL certificate management across the enterprise
Simple steps to take control of SSL across the enterprise, and recommendations for a management platform for full visibility and single-point of control for these Certificates.