Reputation: 1304
I was reading example1 in the following webpage:
http://www.programcreek.com/java-api-examples/index.php?api=javax.jms.QueueBrowser
In the line:
QueueBrowser browser = session.createBrowser(queue1);
where is
queue1
defined?
This is my example of me opening and closing a connection:
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();
}
How would I define a queue in this case?
Upvotes: 2
Views: 731
Reputation: 16056
You can call QueueSession.createQueue(qname). http://docs.oracle.com/javaee/6/api/javax/jms/QueueSession.html#createQueue(java.lang.String)
Upvotes: 1
Reputation: 31832
In your example code the MQXAQueueConnectionFactory
is instantiated empty and then all of the attributes filled in using setter methods. You could take the same approach by instantiating a new and empty destination of type Queue
and then using setter methods to provide sufficient detail for MQ to resolve it to an actual queue.
Alternatively, you could take the approach from Example 3 on the same linked page and look up the queue by establishing a JNDI context and retrieving a pre-existing managed object by name. The managed object can have any or all of the properties documented in Properties of IBM MQ classes for JMS objects.
In either of these cases the queue being opened must already exist on the queue manager. For example, you could specify SYSTEM.DEFAULT.LOCAL.QUEUE
as the queue to be browsed since you can be pretty sure it exists on the queue manager.
Upvotes: 1
Reputation: 45
The createBrowser method expects a queue to be put in. For that you'll need to create a new suitable queue instance.
E.g.
ActiveMQQueue myQueue = new ActiveMQQueue("My queue");
QueueBrowser browser = session.createBrowser(myQueue);
Take a look at this guide if interested: https://examples.javacodegeeks.com/enterprise-java/jms/jms-queuebrowser-example/
Upvotes: 1