简体   繁体   English

检查Solace中是否存在队列

[英]Check if queue exists in Solace

I'm using Java API to connect to Solace, provision queues and subscribe them to topics. 我正在使用Java API连接到Solace,设置队列并将它们订阅到主题。 In case those queues are already exists I would like to avoid doing it again. 如果这些队列已经存在,我想避免再做一次。 Using Java API is it possible to check if particular queue exists and which topics are mapped to that queue? 使用Java API可以检查特定队列是否存在以及哪些主题映射到该队列?

The best way to do this is to attempt to provision, and make use of the JCSMPSession.FLAG_IGNORE_ALREADY_EXISTS and JCSMPProperties.IGNORE_DUPLICATE_SUBSCRIPTION_ERROR properties. 做到这一点的最佳方法是尝试设置并利用JCSMPSession.FLAG_IGNORE_ALREADY_EXISTSJCSMPProperties.IGNORE_DUPLICATE_SUBSCRIPTION_ERROR属性。

Here's an quick example: 这是一个简单的例子:

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);

Note that there's no actual method to verify if the queue and topic subscriptions exist using the API. 请注意,没有使用API​​验证队列和主题订阅是否存在的实际方法。 If absolutely necessary, you can make use of SEMP over message bus to execute show commands, but this is pretty unwieldy. 如果绝对必要,则可以通过消息总线使用SEMP来执行show命令,但这非常麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM