我有一个Spring应用程序,该应用程序使用JMS Solace连接到具有多个订阅的Solace代理。每个订阅都有一个不同的msgVPN和队列值。我能够使用solace-jms-spring-boot-starter创建与一个队列的连接。问题是,当我尝试在同一连接上创建第二个队列时,出现Solace 503错误“未知队列”错误。
理想情况下,我想要一个JMS连接和几个队列,以从所有订阅中检索消息。 Solace可以做到这一点吗,还是我还需要另一种方式?
当前,这就是我试图建立连接的方式。
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
答案 0 :(得分:0)
我发现JMS Solace中每个连接只能有一个队列。因此,如果您需要多个连接,则可以使用不同的登录值创建另一个Connection bean(例如,公共Connection connection2())。
我必须将solConnectionFactory()折叠到我的连接方法中以具有不同的值,但是它现在可以正常工作。