How to capture com.solacesystems.jcsmp.JCSMPErrorResponseException: 503

Hello
I am using com.solacesystems.jms.SolConnection to create a connection to my cloud example.
When I disable the mssage VPN, I get the following error in the wrapper log:
TcpClientChannel 09Jun2020 20:43:36 Connection attempt failed to host ‘xxxxxxx.messaging.solace.cloud’ ReconnectException ((Client name: xxxxxx Local addr: xxxxxx Remote addr: xxxxxxx) - ) com.solacesystems.jcsmp.JCSMPErrorResponseException: 503: Message VPN Unavailable [Subcode:9]

How can I capture this within my java class? I’ve implemented SolConnectionEventListener, but that only gets me “CAUSE: com.solacesystems.jcsmp.JCSMPTransportException: Error receiving data from underlying connection.”

Ok… so you’re shutting down the VPN to simulate a network outage? That’s cool. The API will automatically attempt to reconnect for the amount of times specified in your JCSMPChannelProperties. By default, only once all reconnect attempts have failed will a (transport) exception be thrown up to the application to signal there was a failure.

But if the application wants to be notified of disconnect/reconnect events (e.g. to set a GUI element or something), then you gotta implement the JCSMPReconnectEventHandler when you create the Consumer object: JCSMPSession (Solace Messaging API for Java v10.25.2)

Hope that helps!

I will have to test using a lower retry amount.
I am using jms 1.1. Is there a similar ReconnectEventHanlder for it? I am creating my consumer with javax.session.createConsumer(topic)
Thank you.

Ok… first off… I misread/misunderstood your original question… you were looking to find how to capture the more detailed log/reason information in your exception, correct? Not just have your application be aware of connection issues? If the former, I don’t think you can get the exact reason in the exception.

Anyhow… if it was the latter… in JMS, the JMS specification doesn’t explicitly provide any mechanism to “listen” to disconnect/reconnect events. Only once your connection retry attempts are exhausted does the API throw a JMSException up to the applicaiton. Usually.

But in Solace, there is a way for a JMS app to hook up to these notification events… check out: JMS API

It is possible to register an SolConnectionEventListener to receive callbacks whenever the connection state transitions. Here is an sample snippet:

SolConnectionEventSource eventSource = (SolConnectionEventSource) jmsConnection;
eventSource.setConnectionEventListener(new SolConnectionEventListener() {

@Override
public void onEvent(SolConnectionEvent event) {
System.out.println(event.getType());
}});

Javadocs can be found at:

You will need to search for SolConnectionEventListener.

Awesome, thanks @Aaron! I learned something today :slight_smile: