gpt4 book ai didi

java - 如何为 QueueBrowser 定义一个队列?

转载 作者:行者123 更新时间:2023-11-30 08:01:37 26 4
gpt4 key购买 nike

我正在阅读以下网页中的示例 1:

http://www.programcreek.com/java-api-examples/index.php?api=javax.jms.QueueBrowser

行内:

QueueBrowser browser = session.createBrowser(queue1);

在哪儿

queue1 

定义?

这是我打开和关闭连接的示例:

public static void main(String[] args) throws Exception {
Logger logger = LoggerFactory.getLogger(Connection.class);
String hostname = "xxxxxx";
int port = 1442;
String queueManager = "xxxxxxxx";
String channel = "xxxxxxxxxx";
String queueName = "xxxxxxxxxx";
String keystore = "xxxxxxxxx/xxxxxxx/ssclient_test.ks";
String truststore = "cxxxxxx/xxxxxxxx/client_test.ts";
String suiteName = "xxx_xxx_xxxx_xxx_xxx_xxx";
String keyStorePassKey = "xxx_KEYSTORE";
SSLSocketFactory sslSocketFactory = createSslSocketFactory(new File(keystore), new File(truststore),
keyStorePassKey);
MQXAQueueConnectionFactory mqConnFactory = new MQXAQueueConnectionFactory();
mqConnFactory.setHostName(hostname);
mqConnFactory.setPort(port);
mqConnFactory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
mqConnFactory.setQueueManager(queueManager);
mqConnFactory.setChannel(channel);
mqConnFactory.setUseConnectionPooling(true);
mqConnFactory.setSSLSocketFactory(sslSocketFactory);
mqConnFactory.setSSLCipherSuite(suiteName);
QueueConnection queueConnection = mqConnFactory.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queueSession.close();
queueConnection.close();
}

在这种情况下我将如何定义队列?

最佳答案

createBrowser 方法需要放入一个队列。为此,您需要创建一个新的合适的队列实例。

例如

ActiveMQQueue myQueue = new ActiveMQQueue("My queue");
QueueBrowser browser = session.createBrowser(myQueue);

如果有兴趣,请查看本指南: https://examples.javacodegeeks.com/enterprise-java/jms/jms-queuebrowser-example/

关于java - 如何为 QueueBrowser 定义一个队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37415575/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com