vap
vap

Reputation: 31

Can't connect to multiple Solace queues with different msgVPNs on the same connection

I have a Spring application that is using JMS Solace to connect to a Solace broker that has multiple subscriptions. Each of the subscriptions has a different msgVPN and queue value. I was able to use solace-jms-spring-boot-starter to create a connection to one queue. The problem is when I try to create a second queue on the same connection I get a Solace 503 error 'Unknown Queue' error.

Ideally, I would like to have one JMS connection with several queues to retrieve messages from all the subscriptions. Is this possible with Solace or is there another way I need to do this?

Currently, this is how I am trying to make the connection.

BeanConfig.java

import com.rumack.listener.JmsExceptionListener;
import com.rumack.listener.JmsMessageListener;
import com.solacesystems.jms.SolConnectionFactory;
import com.solacesystems.jms.SolJmsUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.Queue;

@Configuration
@PropertySource({"classpath:application.properties"})
public class BeanConfig {

    private static final Logger logger = LoggerFactory.getLogger(BeanConfig.class);

    @Autowired
    private Environment environment;

    @Autowired
    private JmsExceptionListener exceptionListener;

    @Bean
    public SolConnectionFactory solConnectionFactory() throws Exception {
        SolConnectionFactory connectionFactory = SolJmsUtility.createConnectionFactory();
        connectionFactory.setHost(environment.getProperty("solace.java.host"));
        // Here I have to set the connection to a msgVPN value. 
        // From everything I've seen the VPN needs to be set here.
        connectionFactory.setVPN(environment.getProperty("solace.java.msgVpn"));
        connectionFactory.setUsername(environment.getProperty("solace.java.clientUsername"));
        connectionFactory.setPassword(environment.getProperty("solace.java.clientPassword"));
        connectionFactory.setClientID(environment.getProperty("solace.java.clientName"));
        return connectionFactory;
    }

    @Bean
    public JmsMessageListener jmsMessageListener() {
        return new JmsMessageListener();
    }

    @Bean(destroyMethod = "close")
    public Connection connection() {
        Connection connection = null;
        javax.jms.Session session;

        try {
            connection = solConnectionFactory().createConnection();
            session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

            // This queue will work and return messages because the connection has a vpn msg value set correctly 
            Queue queue = session.createQueue(environment.getProperty("Queue1.solace.message.consumer.queue"));
            MessageConsumer messageConsumer = session.createConsumer(queue);
            messageConsumer.setMessageListener(jmsMessageListener());

            // This queue will not work and crash the app because the connection is set to the other sub and I'm trying to
            // connect to a queue other than the first
            Queue FDPSQueue = session.createQueue(environment.getProperty("Queue2.solace.message.consumer.queue"));
            MessageConsumer messageConsumer1 = session.createConsumer(FDPSQueue);
            messageConsumer1.setMessageListener(jmsMessageListener1());

            connection.setExceptionListener(exceptionListener);
            // Application fails here with a Solace 503 error
            connection.start();
            logger.info("Connected Awaiting message...");

        } catch (Exception e) {
            logger.info("JMS connection failed with Solace." + e.getMessage());
            e.printStackTrace();
        }
        return connection;
    }


}

application.properties

Queue1.solace.message.consumer.queue=acme.queue1.OUT
Queue2.solace.message.consumer.queue=acme.queue2.OUT

solace.java.host=tcps://<url>:<port>
solace.java.clientUsername=<username>
solace.java.clientPassword=<password>
solace.java.msgVpn=msgVPN1
solace.java.clientName=solacetest
solace.java.messageAckMode=client_ack
solace.java.reapplySubscriptions=false

Upvotes: 2

Views: 1403

Answers (1)

vap
vap

Reputation: 31

I found out that you can only have one queue per connection in JMS Solace. So if you need multiple connections you can create another Connection bean (ex public Connection connection2 () ) just with different login values.

I had to fold in solConnectionFactory() into my connection method to have different values but it is working now.

Upvotes: 1

Related Questions