0

I use solace as a JMS provider in my project. I use spring CachingConnectionFactory to retrieve Connection. On that connection I create new session. I have thread with one Consumer created on that session.

@Autowired
CachingConnectionFactory ccf;
Connection connection = ccf.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
MessageConsumer messageConsumer = new session.createConsumer(destination); // This is passed to new thread

I'm doing some failover tests. When I unplug server from network connection, it fails. When I connect server again I'm still receiving the same exception:

javax.jms.IllegalStateException: Error receiving message - already closed (Tried to call receive on a stopped message consumer.) ...

What is more CachingConnectionFactory has "reconnectOnException" property set to "true" by default (and I checked that is works).

Exception seems to be clear. So my question is: How to handle such case/exception when connection is lost and established again? Is it possible to have consumer alive again? Or I should create new consumer and new thread(what I would like to avoid)?

2 Answers2

1

The reconnectOnException property will attempt one reconnect after an exception is received. It is likely that this reconnect fails as the failover is still in progress.

You can configure the Solace API to attempt to reconnect multiple times with the "Reconnect Retry" and "Reconnect Retry Wait" properties in the JNDI Connection Factory. This is configurable on the Solace router through SolAdmin or the CLI. If you configure your application to reconnect long enough for the connection to be established, you should not run into any exceptions. Otherwise, you will need to create the session and consumer again when receiving this exception.

Alexandra Masse
  • 1,277
  • 1
  • 7
  • 11
  • Thank you for explanation. I requested for changing parameters and we will see. I assume that solace api will take care then of recreating connection but shouldn't it recreate sessions and consumers automatically also? – Daniel Urbaniak Jul 11 '18 at 15:09
0

In general, CachingConnectionFactory can support auto reconnection via Connection's onException(). But you used consumer should also be re-created once connection had been re-connected.

You can refer / use spring's DefaultMessageListenerContainer or SimpleMessageListenerContainer, for example, SimpleMessageListenerContainer:

enter image description here

Emman Sun
  • 351
  • 3
  • 15