Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Configuring Websphere for using JMS

    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
    Code:
    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

    Code:
    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
    Code:
    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){}
    	}
    }

  • #2
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i've dont lot of googling on it.. but no use...

    some one please help me...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •