如何从Solace JMS队列接收JSON消息,队列已经创建



我正在尝试从Solace JMS队列接收JSON消息,但没有收到任何消息。下面是我的代码

@Service
public class QueueConsumer {
final String QUEUE_NAME = "test.Request.Q.V01";
// Latch used for synchronizing between threads
final CountDownLatch latch = new CountDownLatch(1);
public void run(String... args) throws Exception {
String host = "test.solace.com";
String vpnName = "TEST_VPN";
String username = "testVpn";
String password = "test123";
System.out.printf("QueueConsumer is connecting to Solace messaging at %s...%n", host);
SolConnectionFactory connectionFactory = SolJmsUtility.createConnectionFactory();
connectionFactory.setHost(host);
connectionFactory.setVPN(vpnName);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
connectionFactory.setDynamicDurables(true);
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, SupportedProperty.SOL_CLIENT_ACKNOWLEDGE);
System.out.printf("Connected to the Solace Message VPN '%s' with client username '%s'.%n", vpnName, username);
Queue queue = session.createQueue(QUEUE_NAME);
MessageConsumer messageConsumer = session.createConsumer(queue);
messageConsumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
try {
if (message instanceof SolaceMsg) {
System.out.printf("TextMessage received: '%s'%n", ((SolaceMsg) message).getClass());
} else {
System.out.println("Message received.");
}
System.out.printf("Message Content:%n%s%n", SolJmsUtility.dumpMessage(message));
message.acknowledge();
latch.countDown(); // unblock the main thread
} catch (JMSException ex) {
System.out.println("Error processing incoming message.");
ex.printStackTrace();
}
}
});
System.out.println("Start receiving messages....");
connection.start();
System.out.println("Awaiting message...");
latch.await();
connection.stop();
messageConsumer.close();
session.close();
connection.close();
}
public static void main(String... args) throws Exception {
new QueueConsumer().run(args);
}
}

我的消息类型是下面的JSON广告,我已经为此创建了一个POJO。

{
"customerDetails": {
"customerID": "0001234",
"customerName": "John"
}
}

我收到一条警告,说Response-400队列已经存在,因为它是一个现有的队列,我没有收到任何消息。我在这里做错了什么?

您的代码片段看起来是正确的。您可以登录到事件代理的PubSub+Manager,以验证客户端是否绑定到正确的队列,以及消息是否已成功发布到队列并等待消费。您还可以启用Solace JMS API日志记录,以了解有关应用程序正在做什么的更多信息:https://docs.solace.com/Solace-JMS-API/Code-and-Compile-Guideli.htm

最新更新