本文整理匯總了Java中javax.jms.TopicSession.createTopic方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicSession.createTopic方法的具體用法?Java TopicSession.createTopic怎麽用?Java TopicSession.createTopic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.TopicSession
的用法示例。
在下文中一共展示了TopicSession.createTopic方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doTestCreateTopicPublisher
import javax.jms.TopicSession; //導入方法依賴的package包/類
private void doTestCreateTopicPublisher(boolean useAnonymousProducers) throws JMSException {
cf.setUseAnonymousProducers(useAnonymousProducers);
JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic1 = session.createTopic("Topic-1");
Topic topic2 = session.createTopic("Topic-2");
JmsPoolTopicPublisher publisher1 = (JmsPoolTopicPublisher) session.createPublisher(topic1);
JmsPoolTopicPublisher publisher2 = (JmsPoolTopicPublisher) session.createPublisher(topic2);
if (useAnonymousProducers) {
assertSame(publisher1.getMessageProducer(), publisher2.getMessageProducer());
} else {
assertNotSame(publisher1.getMessageProducer(), publisher2.getMessageProducer());
}
connection.close();
}
示例2: publishMessagesToTopic
import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
* To publish the messages to a topic.
*
* @throws JMSException JMS Exception.
* @throws InterruptedException Interrupted exception while waiting in between messages.
*/
public void publishMessagesToTopic(String topicName) throws JMSException, InterruptedException {
TopicConnection topicConnection = (TopicConnection) connectionFactory.createConnection();
topicConnection.start();
TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = topicSession.createTopic(topicName);
MessageProducer topicSender = topicSession.createProducer(destination);
topicSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
for (int index = 0; index < 10; index++) {
String topicText = "Topic Message : " + (index + 1);
TextMessage topicMessage = topicSession.createTextMessage(topicText);
topicSender.send(topicMessage);
logger.info("Publishing " + topicText + " to topic " + topicName);
Thread.sleep(1000);
}
topicConnection.close();
topicSession.close();
topicSender.close();
}
示例3: testNotificationProperties
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test
public void testNotificationProperties() throws Exception {
try (TopicConnection topicConnection = factory.createTopicConnection()) {
TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic notificationsTopic = topicSession.createTopic("activemq.notifications");
TopicSubscriber subscriber = topicSession.createSubscriber(notificationsTopic);
List<Message> receivedMessages = new CopyOnWriteArrayList<>();
subscriber.setMessageListener(receivedMessages::add);
topicConnection.start();
Wait.waitFor(() -> receivedMessages.size() > 0);
Assert.assertTrue(receivedMessages.size() > 0);
for (Message message : receivedMessages) {
assertNotNull(message);
assertNotNull(message.getStringProperty("_AMQ_NotifType"));
}
}
}
示例4: testSendAndReceiveOnTopic
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testSendAndReceiveOnTopic() throws Exception {
Connection connection = createConnection("myClientId");
try {
TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(getTopicName());
TopicSubscriber consumer = session.createSubscriber(topic);
TopicPublisher producer = session.createPublisher(topic);
TextMessage message = session.createTextMessage("test-message");
producer.send(message);
producer.close();
connection.start();
message = (TextMessage) consumer.receive(1000);
assertNotNull(message);
assertNotNull(message.getText());
assertEquals("test-message", message.getText());
} finally {
connection.close();
}
}
示例5: collectMessagesFromDurableSubscriptionForOneMinute
import javax.jms.TopicSession; //導入方法依賴的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;
}
示例6: testCreateTopicPublisher
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test
public void testCreateTopicPublisher() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI());
TopicConnection connection = factory.createTopicConnection();
assertNotNull(connection);
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
Topic topic = session.createTopic(name.getMethodName());
TopicPublisher publisher = session.createPublisher(topic);
assertNotNull(publisher);
TopicViewMBean proxy = getProxyToTopic(name.getMethodName());
assertEquals(0, proxy.getEnqueueCount());
connection.close();
}
示例7: createTopic
import javax.jms.TopicSession; //導入方法依賴的package包/類
public static Topic createTopic(String uri, String topicName) throws JMSException {
TopicConnectionFactory connectionFactory = null;
TopicConnection connection = null;
TopicSession session = null;
Topic topic = null;
try {
connectionFactory = new ActiveMQConnectionFactory(uri);
connection = connectionFactory.createTopicConnection();
connection.start();
session = connection.createTopicSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
topic = session.createTopic(topicName);
session.commit();
} finally {
closeQuietly(session);
closeQuietly(connection);
}
return topic;
}
示例8: testCreateTopicPublisher
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testCreateTopicPublisher() throws Exception {
JmsPoolConnection connection = (JmsPoolConnection) pooledFactory.createConnection();
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic1 = session.createTopic("Topic-1");
Topic topic2 = session.createTopic("Topic-2");
JmsPoolTopicPublisher publisher1 = (JmsPoolTopicPublisher) session.createPublisher(topic1);
JmsPoolTopicPublisher publisher2 = (JmsPoolTopicPublisher) session.createPublisher(topic2);
assertNotSame(publisher1.getMessageProducer(), publisher2.getMessageProducer());
}
示例9: testCreateTopicPublisher
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testCreateTopicPublisher() throws Exception {
JmsPoolConnection connection = (JmsPoolConnection) pooledFactory.createConnection();
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic1 = session.createTopic("Topic-1");
Topic topic2 = session.createTopic("Topic-2");
JmsPoolTopicPublisher publisher1 = (JmsPoolTopicPublisher) session.createPublisher(topic1);
JmsPoolTopicPublisher publisher2 = (JmsPoolTopicPublisher) session.createPublisher(topic2);
assertSame(publisher1.getMessageProducer(), publisher2.getMessageProducer());
connection.close();
}
示例10: lookupTopic
import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
* <b>JMS 1.0.2</b>
* @return A valid Topic object created either from JNDI lookup or directly from the given session.
*/
public DestinationWrapper<Topic> lookupTopic(String uri, TopicSession session) throws JMSException, NamingException {
if ( usingJNDI ) {
return lookupTopicFromJNDI( uri );
} else {
return new DestinationWrapper<Topic>( uri, session.createTopic( uri ) );
}
}
示例11: start
import javax.jms.TopicSession; //導入方法依賴的package包/類
public synchronized void start() throws RestException {
try {
// Debug
logger.debug("Creating JMS connection using host: " + jmsHost + " user: " + jmsUser + " passwd: " + jmsPassword);
// Create topic connection factory - connecting directly to VSD,
// bypassing JNDI factory
String brokerUrl = String.format(BROKER_URL_FMT, jmsHost, jmsPort);
TopicConnectionFactory topicConnectionFactory = new ActiveMQConnectionFactory(brokerUrl);
// Create the JMS topic connection and start it
topicConnection = topicConnectionFactory.createTopicConnection(jmsUser, jmsPassword);
topicConnection.start();
// Debug
logger.debug("Subscribing to JMS topic: " + jmsTopic);
// Create the subscriber
TopicSession topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
String[] topicSubNames = jmsTopic.split("/");
String topicName = topicSubNames[topicSubNames.length - 2] + '/' + topicSubNames[topicSubNames.length - 1];
Topic topic = topicSession.createTopic(topicName);
createSubscriber(topicSession, topic);
// Debug
logger.info("JMS connection started");
} catch (JMSException ex) {
throw new RestException(ex);
}
}
示例12: testSendAndReceiveOnAutoCreatedTopic
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testSendAndReceiveOnAutoCreatedTopic() throws Exception {
Connection connection = createConnection("myClientId");
String topicName = UUID.randomUUID().toString();
SimpleString simpleTopicName = SimpleString.toSimpleString(topicName);
try {
TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(topicName);
TopicPublisher producer = session.createPublisher(topic);
TextMessage message = session.createTextMessage("test-message");
// this will auto-create the address, but not the subscription queue
producer.send(message);
assertNotNull(server.getAddressInfo(simpleTopicName));
assertEquals(RoutingType.MULTICAST, server.getAddressInfo(simpleTopicName).getRoutingType());
assertTrue(server.getAddressInfo(simpleTopicName).isAutoCreated());
assertTrue(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
// this will auto-create the subscription queue
TopicSubscriber consumer = session.createSubscriber(topic);
assertFalse(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
producer.send(message);
producer.close();
connection.start();
message = (TextMessage) consumer.receive(1000);
assertNotNull(message);
assertNotNull(message.getText());
assertEquals("test-message", message.getText());
consumer.close();
assertTrue(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
} finally {
connection.close();
}
}
示例13: testSendWithMultipleReceiversOnTopic
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testSendWithMultipleReceiversOnTopic() throws Exception {
Connection connection = createConnection();
try {
TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(getTopicName());
TopicSubscriber consumer1 = session.createSubscriber(topic);
TopicSubscriber consumer2 = session.createSubscriber(topic);
TopicPublisher producer = session.createPublisher(topic);
TextMessage message = session.createTextMessage("test-message");
producer.send(message);
producer.close();
connection.start();
message = (TextMessage) consumer1.receive(1000);
assertNotNull(message);
assertNotNull(message.getText());
assertEquals("test-message", message.getText());
message = (TextMessage) consumer2.receive(1000);
assertNotNull(message);
assertNotNull(message.getText());
assertEquals("test-message", message.getText());
} finally {
connection.close();
}
}
示例14: testTemporarySubscriptionDeleted
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testTemporarySubscriptionDeleted() throws Exception {
Connection connection = createConnection();
try {
TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(getTopicName());
TopicSubscriber myNonDurSub = session.createSubscriber(topic);
assertNotNull(myNonDurSub);
Bindings bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
Assert.assertEquals(2, bindingsForAddress.getBindings().size());
session.close();
final CountDownLatch latch = new CountDownLatch(1);
server.getRemotingService().getConnections().iterator().next().addCloseListener(new CloseListener() {
@Override
public void connectionClosed() {
latch.countDown();
}
});
connection.close();
latch.await(5, TimeUnit.SECONDS);
bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
Assert.assertEquals(1, bindingsForAddress.getBindings().size());
} finally {
connection.close();
}
}
示例15: testMultipleDurableConsumersSendAndReceive
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testMultipleDurableConsumersSendAndReceive() throws Exception {
Connection connection = createConnection("myClientId");
try {
TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(getTopicName());
int numMessages = 100;
TopicSubscriber sub1 = session.createDurableSubscriber(topic, "myPubId1");
TopicSubscriber sub2 = session.createDurableSubscriber(topic, "myPubId2");
TopicSubscriber sub3 = session.createDurableSubscriber(topic, "myPubId3");
Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = sendSession.createProducer(topic);
connection.start();
for (int i = 0; i < numMessages; i++) {
producer.send(sendSession.createTextMessage("message:" + i));
}
for (int i = 0; i < numMessages; i++) {
TextMessage receive = (TextMessage) sub1.receive(5000);
Assert.assertNotNull(receive);
Assert.assertEquals(receive.getText(), "message:" + i);
receive = (TextMessage) sub2.receive(5000);
Assert.assertNotNull(receive);
Assert.assertEquals(receive.getText(), "message:" + i);
receive = (TextMessage) sub3.receive(5000);
Assert.assertNotNull(receive);
Assert.assertEquals(receive.getText(), "message:" + i);
}
} finally {
connection.close();
}
}