本文整理匯總了Java中javax.jms.TopicConnection.setClientID方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicConnection.setClientID方法的具體用法?Java TopicConnection.setClientID怎麽用?Java TopicConnection.setClientID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.TopicConnection
的用法示例。
在下文中一共展示了TopicConnection.setClientID方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: collectMessagesFromDurableSubscriptionForOneMinute
import javax.jms.TopicConnection; //導入方法依賴的package包/類
private Message collectMessagesFromDurableSubscriptionForOneMinute() throws Exception {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName);
TopicConnection connection = connectionFactory.createTopicConnection();
connection.setClientID(clientID);
TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = topicSession.createTopic(topicName);
connection.start();
TopicSubscriber subscriber = topicSession.createDurableSubscriber(topic, durableSubName);
LOG.info("About to receive messages");
Message message = subscriber.receive(120000);
subscriber.close();
connection.close();
LOG.info("collectMessagesFromDurableSubscriptionForOneMinute done");
return message;
}
示例2: registerDurableSubscription
import javax.jms.TopicConnection; //導入方法依賴的package包/類
private void registerDurableSubscription() throws JMSException {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName);
TopicConnection connection = connectionFactory.createTopicConnection();
connection.setClientID(clientID);
TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = topicSession.createTopic(topicName);
TopicSubscriber durableSubscriber = topicSession.createDurableSubscriber(topic, durableSubName);
connection.start();
durableSubscriber.close();
connection.close();
LOG.info("Durable Sub Registered");
}
示例3: testNonDurableSubscriberInvalidUnsubscribe
import javax.jms.TopicConnection; //導入方法依賴的package包/類
/**
* Test introduced as a result of a TCK failure.
*/
@Test
public void testNonDurableSubscriberInvalidUnsubscribe() throws Exception {
TopicConnection conn = createTopicConnection();
conn.setClientID("clientIDxyz123");
TopicSession ts = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
try {
ts.unsubscribe("invalid-subscription-name");
ProxyAssertSupport.fail("this should fail");
} catch (javax.jms.InvalidDestinationException e) {
// OK
}
}
示例4: testInvalidSelectorOnSubscription
import javax.jms.TopicConnection; //導入方法依賴的package包/類
@Test
public void testInvalidSelectorOnSubscription() throws Exception {
TopicConnection c = createTopicConnection();
c.setClientID("something");
TopicSession s = c.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
try {
s.createSubscriber(ActiveMQServerTestCase.topic1, "=TEST 'test'", false);
ProxyAssertSupport.fail("this should fail");
} catch (InvalidSelectorException e) {
// OK
}
}
示例5: main
import javax.jms.TopicConnection; //導入方法依賴的package包/類
public static void main(String[] args) {
if (args.length != 2) {
System.err.println("usage: JMS_Publisher <server> <port>");
} else {
TopicConnectionFactory connectionFactory;
try {
connectionFactory = ImaJmsFactory.createTopicConnectionFactory();
ImaProperties imaProperties = (ImaProperties) connectionFactory;
imaProperties.put("Server", args[0]);
imaProperties.put("Port", args[1]);
ImaJmsException[] exceptions = imaProperties.validate(false);
if (exceptions != null) {
for (ImaJmsException e : exceptions) {
System.out.println(e.getMessage());
}
return;
} else {
TopicConnection connection = connectionFactory.createTopicConnection();
String clientId = "JMS_Publisher";
connection.setClientID(clientId);
TopicSession session = connection.createTopicSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Topic topic = session.createTopic("expirationTest");
TopicPublisher publisher = session.createPublisher(topic);
TextMessage message1 = session.createTextMessage("message1");
publisher.publish(message1);
TextMessage message2 = session.createTextMessage("message2");
// Send this with an expiration time ten seconds from now
publisher.publish(message2, DeliveryMode.PERSISTENT, 3, 10000);
TextMessage message3 = session.createTextMessage("message3");
publisher.publish(message3);
System.out.println("Messages published");
}
} catch (JMSException e2) {
e2.printStackTrace();
}
}
}