ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » How to implement Pub/Sub messaging domain using JMS in MQSer

Post new topic  Reply to topic
 How to implement Pub/Sub messaging domain using JMS in MQSer « View previous topic :: View next topic » 
Author Message
eswarnv
PostPosted: Thu Jan 31, 2002 10:25 am    Post subject: Reply with quote

Voyager

Joined: 20 Dec 2001
Posts: 88

Hi All,

Can any one suggest me good documentation or tutorial which explains the entire procedure of implementing publish/subscribe messaging style using JMS on MQSeries.


Thanks in Advance
Eswar
Back to top
View user's profile Send private message
kolban
PostPosted: Thu Jan 31, 2002 1:22 pm    Post subject: Reply with quote

Grand Master

Joined: 22 May 2001
Posts: 1072
Location: Fort Worth, TX, USA

The IBM MQSeries - Using Java Manual

http://www-4.ibm.com/software/ts/mqseries/library/manual01/csqzaw07/csqzaw07tfrm.htm

Should be the place to go ...
Back to top
View user's profile Send private message
abmanesh
PostPosted: Fri Feb 01, 2002 8:05 am    Post subject: Reply with quote

Apprentice

Joined: 06 Nov 2001
Posts: 39

The steps involved implementing Publish/Subscribe messaging with MQ/JMS is illustrated with simple sample programs.

SECTION 1.

Define the JMS Administered objects
Create a JNDI context.
The following command was used to create the JNDI context named ‘ psCtx‘ used in our sample programs.

DEF CTX(psCtx)
Change to the context you just created
CHG CTX(psCtx)
Create a TopicConnectionFactory .
The following command creates a TopicConnectionFactory named ‘psTcf ’
referring to the QueueManager ‘ITSOG.QMGR1 ’ on host named ‘ITSOG ’
listening on the default port 1414 .The server connection channel used
for client connection is ‘JMS.SRV.CHNL ’

DEF TCF(psTcf) TRANSPORT(CLIENT) QMANAGER(ITSOG.QMGR1) HOST(ITSOG)
PORT(1414) CHANNEL(JMS.SRV.CHNL) BROKERQMGR(ITSOG.QMGR1)
BROKERCONQ(SYSTEM.BROKER.CONTROL.QUEUE)
BROKERPUBQ(SYSTEM.BROKER.DEFAULT.STREAM)
BROKERSUBQ(SYSTEM.JMS.ND.SUBSCRIBER.QUEUE)
BROKERCCSUBQ(SYSTEM.JMS.ND.CC.SUBSCRIBER.QUEUE)

Define the JNDI topic
The following command creates a Topic named ‘psTopic ’ for the topic
named SampleTopic under the root topic of JmsTest.
DEF T(psTopic)TOPIC(JMSTest/SampleTopic)

SECTION 2.

The program JMSPublisher.java will create
a text message and publish it to a topic 'SampleTopic' which is under the root
topic of JMSTest. We will also illustrate the subscriber program that will
subscribe to the topic 'SampleTopic'. The High level Steps involved in the Publisher are

A. Lookup the JNDI namespace for the TopicConnectionFactory and the To p i c
B. Create a Topic Connection
C. Create a TopicSession
D. Create a TopicPublisher
E. Create a TextMessage
F. Publish the message to the Topic
G. Close and disconnect the connection objects.


JMSPublisher.java
//Step 1 Import the necessary packages
import java.util.*;
import javax.jms.*;
import javax.naming.directory.*;
import javax.naming.*;
public class JMSPublisher {
/**
*The main method
*@param no args
*/
public static void main(String [] args)){
String topicName ="cn=psTopic";
String tcfName ="cn=psTcf";
Context jndiContext =null;
TopicConnectionFactory topicConnectionFactory =null;
TopicConnection topicConnection =null;
TopicSession topicSession =null;
Topic topic =null;
TopicPublisher publisher =null;
TextMessage message =null;
String providerUrl ="ldap://itsog/cn=psCtx,o=itsog,c=uk";
String initialContextFactory ="com.sun.jndi.ldap.LdapCtxFactory";
//Step 2 Set up an Initial context for JNDI lookUp.
try {
Hashtable env =new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,initialContextFactory);
env.put(Context.PROVIDER_URL ,providerUrl );
jndiContext =new InitialDirContext(env);
//Step 3 Obtain a TopicConnection factory
topicConnectionFactory =
(TopicConnectionFactory)jndiContext.lookup(tcfName);
//Step 4 Create a Topic Connection using the connection factory object
topicConnection =topicConnectionFactory.createTopicConnection();
//Step 5 Start the topic connection.
topicConnection.start();

//Step 6 Obtain a Topic from the JNDI
topic =(Topic)jndiContext.lookup(topicName);
//Step 7 Create a Topic Session from the topic connection
topicSession =topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
//Step 8 Create a topic publisher for the topic from the session.
publisher =topicSession.createPublisher(topic);
//Step 9 Create a message object
message =topicSession.createTextMessage();
//Step 10 prepare the body of the message
message.setText("This is a Test Message from JMSPublisher Class ")
;
//Step 11 Publish the message.
publisher.publish(message);
//Step 12 Close the connections.
publisher.close();
topicSession.close();
topicConnection.close();
}
catch(Exception e ){
e.printStackTrace();
}
}
}

Simple JMS Subscriber Application.
In this section we will illustrate the steps involved in developing a JMS
Subscriber application with a simple JMS subscriber application.
The high level steps involved in writing a JMS Subscriber application are:

A. Lookup the JNDI namespace for the TopicConnectionFactory and the To p i c
B. Create a Topic Connection
C. Create a TopicSession
D. Create a TopicSubscriber
E. Receive subscription from the Topic
F. Close and disconnect the connection objects.

The program JMSSubscriber.java is a simple subscriber application that will
subscribe to messages from the topic 'SampleTopic' which is under the root
topic of JMSTest. We will be using non durable subscription in the sample.

JMSSubscriber.java
//Step 1 Import the necessary packages.

import java.util.*;
import javax.jms.*;
import javax.naming.directory.*;
import javax.naming.*;
public class JMSSubscriber {
/**
*The main method
*@param no args
*/
public static void main(String [] args)){
String topicName ="cn=psTopic";
String tcfName ="cn=psTcf";
Context jndiContext =null;
TopicConnectionFactory topicConnectionFactory =null;
TopicConnection topicConnection =null;
TopicSession topicSession =null;
Topic topic =null;
TopicSubscriber subscriber =null;
TextMessage message =null;
String providerUrl ="ldap://itsog/cn=psCtx,o=itsog,c=uk";
String initialContextFactory ="com.sun.jndi.ldap.LdapCtxFactory";
//Step 2 Set up Initial Context for JNDI lookup
try{
Hashtable env =new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,initialContextFactory);
env.put(Context.PROVIDER_URL ,providerUrl );
env.put(Context.REFERRAL,"throw");
jndiContext =new InitialDirContext(env);
//Step 3 Get the TopicConnection factory from the JNDI Namespace
topicConnectionFactory =
(TopicConnectionFactory)jndiContext.lookup(tcfName);
//Step 4 Create a TopicConnection
topicConnection =topicConnectionFactory.createTopicConnection();
//Step 5 Start The topic connection
topicConnection.start();
//Step 6 Create a topic session from the topic connection
topicSession =topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
//Step 7 Obtain a Topic from the JNDI namespace
topic =(Topic)jndiContext.lookup(topicName);
//Step 8 Create a topic subscriber for the topic.
subscriber =topicSession.createSubscriber(topic);//Non durable
subscriber
//Step 9 Receive Subscription
message =(TextMessage)subscriber.receive();
System.out.println("n ***The Message is "+message.getText());

//Step 10Close the connection and other open resources
subscriber.close();
topicSession.close();
topicConnection.close();
}
catch(Exception e ){
e.printStackTrace();
}
}
}

[ This Message was edited by: abmanesh on 2002-02-01 08:07 ]

[ This Message was edited by: abmanesh on 2002-02-01 08:08 ]
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » How to implement Pub/Sub messaging domain using JMS in MQSer
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.