Fails to reconnect to JMS server after restarting weblogic server - Weblogic

This is a discussion on Fails to reconnect to JMS server after restarting weblogic server - Weblogic ; HI: I try to reconnect to JMS server after restarting weblogic server. I thought it was straightfoward. I add code for the exception handling of jms msg publish(). The code basically does all JMS initialization steps. It turns out the ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Fails to reconnect to JMS server after restarting weblogic server

  1. Fails to reconnect to JMS server after restarting weblogic server


    HI:

    I try to reconnect to JMS server after restarting weblogic server.
    I thought it was straightfoward. I add code for the exception handling of jms
    msg publish(). The code basically
    does all JMS initialization steps. It turns out the it works only with webligic.jar,
    and it does not work with thin client.
    Anybody knows why ? Since with weblogic.jar it works,
    I believe the code is correct. Now, what's wrong with the thin client?

    For example, I just takes Sun example TopicSend.java,
    and add code in main:

    public static void main(String[] args) throws Exception {
    if (args.length != 1) {
    System.out.println("Usage: java examples.jms.topic.TopicSend WebLogicURL");
    return;
    }
    InitialContext ic = getInitialContext("t3://10.1.3.126:7001");
    TopicSend ts = new TopicSend();
    ts.init(ic, TOPIC);
    readAndSend(ts);
    try
    {
    //let it sleep, so that I can restart weblogic server
    Thread.sleep (60000);
    } catch (Exception e) {}

    try {
    readAndSend(ts);

    } catch (Exception e)
    {
    System.out.println ("after restart weblogic: read error=" + e.toString());
    ts.close();
    ic.close();
    try {
    ic = getInitialContext("t3://10.1.3.126:7001");
    ts.init(ic, "MY_TOPIC"); //MY_TOPIC configured in server
    readAndSend(ts);
    } catch (Exception e1)
    {
    System.out.println ("reconnection error=" + e.toString());
    }
    }
    ts.close();
    }


    Thanks,

    Tony



  2. Re: Fails to reconnect to JMS server after restarting weblogic server

    There is not enough detail in the code below, and you did
    not post the exception. My bet is that the application
    is not coded to get a new connection from the connection
    factory, but is instead attempting
    to re-use the old connection - which is now invalid.

    Standard practice is to close all resources and
    clean up application state on failure, and then
    retry the connect, etc...

    Tom

    tony wrote:

    > HI:
    >
    > I try to reconnect to JMS server after restarting weblogic server.
    > I thought it was straightfoward. I add code for the exception handling of jms
    > msg publish(). The code basically
    > does all JMS initialization steps. It turns out the it works only with webligic.jar,
    > and it does not work with thin client.
    > Anybody knows why ? Since with weblogic.jar it works,
    > I believe the code is correct. Now, what's wrong with the thin client?
    >
    > For example, I just takes Sun example TopicSend.java,
    > and add code in main:
    >
    > public static void main(String[] args) throws Exception {
    > if (args.length != 1) {
    > System.out.println("Usage: java examples.jms.topic.TopicSend WebLogicURL");
    > return;
    > }
    > InitialContext ic = getInitialContext("t3://10.1.3.126:7001");
    > TopicSend ts = new TopicSend();
    > ts.init(ic, TOPIC);
    > readAndSend(ts);
    > try
    > {
    > //let it sleep, so that I can restart weblogic server
    > Thread.sleep (60000);
    > } catch (Exception e) {}
    >
    > try {
    > readAndSend(ts);
    >
    > } catch (Exception e)
    > {
    > System.out.println ("after restart weblogic: read error=" + e.toString());
    > ts.close();
    > ic.close();
    > try {
    > ic = getInitialContext("t3://10.1.3.126:7001");
    > ts.init(ic, "MY_TOPIC"); //MY_TOPIC configured in server
    > readAndSend(ts);
    > } catch (Exception e1)
    > {
    > System.out.println ("reconnection error=" + e.toString());
    > }
    > }
    > ts.close();
    > }
    >
    >
    > Thanks,
    >
    > Tony
    >
    >



  3. Re: Fails to reconnect to JMS server after restarting weblogic server


    Tom:

    Yes, I do it the way you describe.
    After getting exception, I do:
    ts.close();
    ic.close();

    ic = getInitialContext("t3://10.1.3.126:7001");
    ts.init(ic, TOPIC);

    Here is init():

    public void init(Context ctx, String topicName)
    throws NamingException, JMSException
    {
    tconFactory = (TopicConnectionFactory)
    PortableRemoteObject.narrow(ctx.lookup(JMS_FACTORY ),
    TopicConnectionFactory.class);
    tcon = tconFactory.createTopicConnection();
    tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    topic = (Topic) PortableRemoteObject.narrow(ctx.lookup(topicName), Topic.class);
    tpublisher = tsession.createPublisher(topic);
    msg = tsession.createTextMessage();
    tcon.start();
    }


    Please be aware that it works with the fat client.

    I just notice somebody before my first post posted a msg and it answered my
    question actually.


    Tony

+ Reply to Thread