Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:52:10+00:00 2026-06-09T07:52:10+00:00

I am having an issue with a JMS re-connect strategy. I’m not sure if

  • 0

I am having an issue with a JMS re-connect strategy. I’m not sure if I am doing it correctly (Most likely I am not). Anyways, I am using WebLogic, and this is a consumer client. Here’s how I gain a connection, and try to add the automatic re-connect. The problem is that it doesn’t reconnect, and there are no exceptions logging what-so-ever. I re-create the situation by starting weblogic, starting consumer client which gains initial connection, I close weblogic abrubtly, then I re-start weblogic at which point any messages in the queue which this consumer is listening to remain on the queue without being acknowledged since they are not being received.

public void setReceiver(MessageListener listener) {
        try {
            Properties parm = new Properties();
            parm.setProperty("java.naming.factory.initial",
                    "weblogic.jndi.WLInitialContextFactory");
            parm.setProperty("java.naming.provider.url", URL);
            parm.setProperty("java.naming.security.principal", username);
            parm.setProperty("java.naming.security.credentials", password);
            ctx = new InitialContext(parm);
            final QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx
                    .lookup(conFactoryName);
            connection = connectionFactory.createQueueConnection();
            // TODO: 8/6/2012 Work on reconnection strategies for Consumer.
            ((WLConnection) connection)
                    .setReconnectPolicy(JMSConstants.RECONNECT_POLICY_ALL);
            ((WLConnection) connection).setReconnectBlockingMillis(30000L);
            ((WLConnection) connection).setTotalReconnectPeriodMillis(-1L);
            session = connection.createQueueSession(false,
                    Session.AUTO_ACKNOWLEDGE);

            queue = (Queue) ctx.lookup(queueName);
            // receiver = session.createReceiver(queue);
            // receiver.setMessageListener(listener);
            consumer = session.createConsumer(queue);
            consumer.setMessageListener(listener);

            connection.setExceptionListener(new ExceptionListener() {

                @Override
                public void onException(JMSException arg0) {
                    // Assume Disconnected.
                    FileHandler fh = null;
                    try {
                        fh = new FileHandler("./logs/ExceptionListener", true);
                    } catch (SecurityException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    SimpleFormatter formatter = new SimpleFormatter();
                    fh.setFormatter(formatter);
                    Logger log2 = Logger.getLogger("ExceptionListener");
                    log2.addHandler(fh);
                    boolean connected = false;
                    do {
                        if (connection != null) {
                            try {
                                connection.close();
                            } catch (JMSException e) {
                                log.warning(e.toString());
                            }
                            try {
                                connection = connectionFactory.createQueueConnection();
                                connection.setExceptionListener(this);
                                connection.start();
                                connected = true;
                            } catch (JMSException e) {
                                log.severe(e.toString());
                            }
                        }
                    } while (!connected);

                }
            });
            connection.start();

        } catch (JMSException je) {
            log.severe(je.getMessage());
        } catch (Exception e) {
            log.severe(e.getMessage());
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:52:12+00:00Added an answer on June 9, 2026 at 7:52 am

    So I finally figured out the issue. The main problem with the exception listener not being called was due to having competing jars in my build path. I had wlfullclient.jar and wljmsclient.jar and wlsasclient.jar in my build path After removing wljmsclient.jar and wlsasclient.jar, I started to receive error messages which allowed me to debug further. Here’s my final solution which will try to connect every 30 seconds on the initial connection, and then it will try to re-connect every 30 seconds if it has gained a connection, but then has lost it:

    public boolean setReceiver(MessageListener listener) {
            try {
                Properties parm = new Properties();
                parm.setProperty("java.naming.factory.initial",
                        "weblogic.jndi.WLInitialContextFactory");
                parm.setProperty("java.naming.provider.url", URL);
                parm.setProperty("java.naming.security.principal", username);
                parm.setProperty("java.naming.security.credentials", password);
                ctx = new InitialContext(parm);
                final QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx
                        .lookup(conFactoryName);
                connection = connectionFactory.createQueueConnection();
                ((WLConnection) connection)
                        .setReconnectPolicy(JMSConstants.RECONNECT_POLICY_ALL);
                ((WLConnection) connection).setReconnectBlockingMillis(30000L);
                ((WLConnection) connection).setTotalReconnectPeriodMillis(-1L);
                session = connection.createQueueSession(false,
                        Session.AUTO_ACKNOWLEDGE);
                queue = (Queue) ctx.lookup(queueName);
                consumer = session.createConsumer(queue);
                consumer.setMessageListener(listener);
    
                connection.setExceptionListener(new ExceptionListener() {
                    @Override
                    public void onException(JMSException arg0) {
                        // Assume Disconnected.
                        Logger log2 = new MyLogger().getLogger("BPEL Client");
                        if (arg0 instanceof LostServerException) {
                            log2.severe("Connection to the Server has been lost, will retry in 30 seconds. "
                                    + arg0.toString());
                        } else {
                            log2.severe(arg0.toString());
                        }
    
                    }
                });
                connection.start();
                log.info("Successfully connected to " + URL);
                return true;
            } catch (JMSException je) {
                log.severe("Could not connect to the WebLogic Server, will retry in 30 seconds. "
                        + je.getMessage());
                try {
                    Thread.sleep(30000L);
                } catch (InterruptedException e) {
                    log.warning(e.toString());
                }
                return setReceiver(listener);
            } catch (Exception e) {
                log.severe("Could not connect to the WebLogic Server, will retry in 30 seconds. "
                        + e.toString());
                try {
                    Thread.sleep(30000L);
                } catch (InterruptedException ie) {
                    log.warning(ie.toString());
                }
                return setReceiver(listener);
    
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using MSDTC for SQL transactions. I am having issue with setting up
I am having issue with my pagemethod + url rewrite. When using regular URL:
I am having issue in checking which input has been clicked using unobstructive javascript.
I'm having issue working with json_decode() in PHP. Im using the json2.js library to
I am trying to implement BST algorithm using Cormen's pseudo code yet having issue.
I am having issue making a form be sent using ajax. Here is my
i'm trying to create an application using three20 but i'm having issue to set
I'm working on a PIC 18f4685 using MPLabs C18 C-compiler and I'm having issue
Having issue with slider navigation. Works perfectly fine when there are no other unordered
I having issue that content assistant / intellisense is working in methods such as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.