Feeds

Programming message services in Java

Asynchronous interactions seem to be the way of the future

Business security measures using SSL

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>"); 
   }
}

New hybrid storage solutions

Next page: The consumer

More from The Register

next story
'Windows 9' LEAK: Microsoft's playing catchup with Linux
Multiple desktops and live tiles in restored Start button star in new vids
Not appy with your Chromebook? Well now it can run Android apps
Google offers beta of tricky OS-inside-OS tech
New 'Cosmos' browser surfs the net by TXT alone
No data plan? No WiFi? No worries ... except sluggish download speed
SUSE Linux owner Attachmate gobbled by Micro Focus for $2.3bn
Merger will lead to mainframe and COBOL powerhouse
iOS 8 release: WebGL now runs everywhere. Hurrah for 3D graphics!
HTML 5's pretty neat ... when your browser supports it
Greater dev access to iOS 8 will put us AT RISK from HACKERS
Knocking holes in Apple's walled garden could backfire, says securo-chap
NHS grows a NoSQL backbone and rips out its Oracle Spine
Open source? In the government? Ha ha! What, wait ...?
Google extends app refund window to two hours
You now have 120 minutes to finish that game instead of 15
Intel: Hey, enterprises, drop everything and DO HADOOP
Big Data analytics projected to run on more servers than any other app
prev story

Whitepapers

Providing a secure and efficient Helpdesk
A single remote control platform for user support is be key to providing an efficient helpdesk. Retain full control over the way in which screen and keystroke data is transmitted.
WIN a very cool portable ZX Spectrum
Win a one-off portable Spectrum built by legendary hardware hacker Ben Heck
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.
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?
Security and trust: The backbone of doing business over the internet
Explores the current state of website security and the contributions Symantec is making to help organizations protect critical data and build trust with customers.