检查队列中是否存在Solace

问题描述:

我正在使用Java API连接到Solace,提供队列并将它们订阅到主题。如果这些队列已经存在,我想避免再次这样做。使用Java API可以检查特定队列是否存在以及哪些主题映射到该队列?检查队列中是否存在Solace

执行此操作的最佳方法是尝试设置并使用JCSMPSession.FLAG_IGNORE_ALREADY_EXISTSJCSMPProperties.IGNORE_DUPLICATE_SUBSCRIPTION_ERROR属性。

下面是一个简单的例子:

JCSMPProperties properties = new JCSMPProperties(); 
properties.setProperty(JCSMPProperties.HOST, "your_router_dns_name"); 
properties.setProperty(JCSMPProperties.USERNAME, "default"); 
properties.setBooleanProperty(JCSMPProperties.IGNORE_DUPLICATE_SUBSCRIPTION_ERROR, true); 

JCSMPSession session = JCSMPFactory.onlyInstance().createSession(properties); 

Queue queue = JCSMPFactory.onlyInstance().createQueue("myqueue"); 
EndpointProperties props = new EndpointProperties(); // default properties, modify as needed 
session.provision(queue, props, JCSMPSession.FLAG_IGNORE_ALREADY_EXISTS); 

Topic topic = JCSMPFactory.onlyInstance().createTopic("my/topic"); 
session.addSubscription(queue, topic, JCSMPSession.WAIT_FOR_CONFIRM); 

注意,有没有实际的方法来验证,如果队列和主题订阅存在使用API​​。如果绝对必要,您可以使用SEMP over message bus执行show命令,但这非常笨拙。