...

View Full Version : Configuring Websphere for using JMS



chap_hyd
03-15-2005, 07:51 AM
i'm trying to implement publisher-subscriber model of JMS.. i have written the java applications using the JMS service but no idea how to configure WebSphere to use JMS service..

i'm alos attaching the code that i wrote...

Publisher


import javax.jms.*;
import javax.naming.*;
import java.util.*;

public class MyPublisher
{
public static void main(String args[]) throws Exception
{
Hashtable ht=new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");

InitialContext ic=new InitialContext(ht);

TopicConnectionFactory tcf=(TopicConnectionFactory)ic.lookup("javax.jms.TopicConnectionFactory");
TopicConnection tc=tcf.createTopicConnection();
TopicSession ts=tc.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
Topic t=(Topic)ic.lookup("MyTopic");
TopicPublisher tp=ts.createPublisher(t);
tc.start();
TextMessage tm=ts.createTextMessage();

System.out.println("publisher started");
java.io.DataInputStream dis=new java.io.DataInputStream(System.in);
String message=null;
while(true)
{
System.out.print("Enter Message: ");
message=dis.readLine();
tm.setText(message);
tp.publish(tm);
}
}
}


non-durable subscriber



import javax.jms.*;
import javax.naming.*;
import java.util.*;

public class MyNonDurSub
{
public static void main(String args[]) throws Exception
{
Hashtable ht=new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");

InitialContext ic=new InitialContext(ht);

TopicConnectionFactory tcf=(TopicConnectionFactory)ic.lookup("javax.jms.TopicConnectionFactory");
TopicConnection tc=tcf.createTopicConnection();
TopicSession ts=tc.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
Topic t=(Topic)ic.lookup("MyTopic");
TopicSubscriber tsub=ts.createSubscriber(t);
tsub.setMessageListener(new MyListener());
tc.start();

while(true)
{
Thread.sleep(5000);
}
}
}


MyListener.java


import javax.jms.*;

public class MyListener implements MessageListener
{
public void onMessage(Message m)
{
try{
TextMessage tm=(TextMessage)m;
System.out.println(tm.getText());
}
catch(Exception e){}
}
}

chap_hyd
03-19-2005, 11:41 AM
i've dont lot of googling on it.. but no use... :(

some one please help me...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum