本文整理匯總了Java中javax.jms.TopicSession.createPublisher方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicSession.createPublisher方法的具體用法?Java TopicSession.createPublisher怎麽用?Java TopicSession.createPublisher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.TopicSession
的用法示例。
在下文中一共展示了TopicSession.createPublisher方法的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: testGetTopic
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test
public void testGetTopic() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createTopicConnection();
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTemporaryTopic();
TopicPublisher publisher = session.createPublisher(topic);
assertNotNull(publisher.getTopic());
assertSame(topic, publisher.getTopic());
publisher.close();
try {
publisher.getTopic();
fail("Cannot read topic on closed publisher");
} catch (IllegalStateException ise) {}
}
示例3: testGetTopicPublisher
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test
public void testGetTopicPublisher() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createTopicConnection();
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTemporaryTopic();
JmsPoolTopicPublisher publisher = (JmsPoolTopicPublisher) session.createPublisher(topic);
assertNotNull(publisher.getTopicPublisher());
assertTrue(publisher.getTopicPublisher() instanceof MockJMSTopicPublisher);
publisher.close();
try {
publisher.getTopicPublisher();
fail("Cannot read state on closed publisher");
} catch (IllegalStateException ise) {}
}
示例4: testSenderAndPublisherDest
import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testSenderAndPublisherDest() throws Exception {
JmsPoolXAConnectionFactory pcf = new JmsPoolXAConnectionFactory();
pcf.setConnectionFactory(new ActiveMQXAConnectionFactory(
"vm://test?broker.persistent=false&broker.useJmx=false"));
QueueConnection connection = pcf.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(session.createQueue("AA"));
assertNotNull(sender.getQueue().getQueueName());
connection.close();
TopicConnection topicConnection = pcf.createTopicConnection();
TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher topicPublisher = topicSession.createPublisher(topicSession.createTopic("AA"));
assertNotNull(topicPublisher.getTopic().getTopicName());
topicConnection.close();
pcf.stop();
}
示例5: publish
import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
* @param topicConnection
* @param chatTopic
* @param userId
* @throws JMSException
* @throws IOException
*/
void publish(TopicConnection topicConnection, Topic chatTopic, String userId)
throws JMSException, IOException {
TopicSession tsession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
TopicPublisher topicPublisher = tsession.createPublisher(chatTopic);
topicConnection.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
while (true) {
String msgToSend = reader.readLine();
if (msgToSend.equalsIgnoreCase("exit")) {
topicConnection.close();
System.exit(0);
} else {
TextMessage msg = (TextMessage) tsession.createTextMessage();
msg.setText("\n["+userId + " : " + msgToSend+"]");
topicPublisher.publish(msg);
}
}
}
示例6: send
import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
* Sends the given {@code events} to the configured JMS Topic. It takes the current Unit of Work
* into account when available. Otherwise, it simply publishes directly.
*
* @param events the events to publish on the JMS Message Broker
*/
protected void send(List<? extends EventMessage<?>> events) {
try (TopicConnection topicConnection = connectionFactory.createTopicConnection()) {
int ackMode = isTransacted ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE;
TopicSession topicSession = topicConnection.createTopicSession(isTransacted, ackMode);
try (TopicPublisher publisher = topicSession.createPublisher(topic)) {
for (EventMessage event : events) {
Message jmsMessage = messageConverter.createJmsMessage(event, topicSession);
doSendMessage(publisher, jmsMessage);
}
} finally {
handleTransaction(topicSession);
}
} catch (JMSException ex) {
throw new EventPublicationFailedException(
"Unable to establish TopicConnection to JMS message broker.", ex);
}
}
示例7: 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();
}
}
示例8: testPersistentMessagesForTopicDropped
import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
* Topics shouldn't hold on to messages if there are no subscribers
*/
@Test
public void testPersistentMessagesForTopicDropped() throws Exception {
TopicConnection topicConn = createTopicConnection();
TopicSession sess = topicConn.createTopicSession(true, 0);
TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1);
pub.setDeliveryMode(DeliveryMode.PERSISTENT);
Message m = sess.createTextMessage("testing123");
pub.publish(m);
sess.commit();
topicConn.close();
checkEmpty(ActiveMQServerTestCase.topic1);
}
示例9: testPersistentMessagesForTopicDropped2
import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
* Topics shouldn't hold on to messages when the non-durable subscribers close
*/
@Test
public void testPersistentMessagesForTopicDropped2() throws Exception {
TopicConnection topicConn = createTopicConnection();
topicConn.start();
TopicSession sess = topicConn.createTopicSession(true, 0);
TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1);
TopicSubscriber sub = sess.createSubscriber(ActiveMQServerTestCase.topic1);
pub.setDeliveryMode(DeliveryMode.PERSISTENT);
Message m = sess.createTextMessage("testing123");
pub.publish(m);
sess.commit();
// receive but rollback
TextMessage m2 = (TextMessage) sub.receive(3000);
ProxyAssertSupport.assertNotNull(m2);
ProxyAssertSupport.assertEquals("testing123", m2.getText());
sess.rollback();
topicConn.close();
checkEmpty(ActiveMQServerTestCase.topic1);
}
示例10: createPublisher
import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
* Create a topic publisher
*
* @param topic The topic
* @return The publisher
* @throws JMSException Thrown if an error occurs
*/
@Override
public TopicPublisher createPublisher(final Topic topic) throws JMSException {
lock();
try {
TopicSession session = getTopicSessionInternal();
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createPublisher " + session + " topic=" + topic);
}
TopicPublisher result = session.createPublisher(topic);
result = new ActiveMQRATopicPublisher(result, this);
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createdPublisher " + session + " publisher=" + result);
}
addProducer(result);
return result;
} finally {
unlock();
}
}
示例11: testAllMethodsThrowAfterConnectionClose
import javax.jms.TopicSession; //導入方法依賴的package包/類
public void testAllMethodsThrowAfterConnectionClose() throws Exception
{
// give external brokers a chance to start up
Thread.sleep(3000);
AMQConnection connection = (AMQConnection) getConnection("guest", "guest");
Topic destination1 = new AMQTopic(connection, "t1");
TopicSession session1 = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher pub = session1.createPublisher(destination1);
connection.close();
try
{
pub.getDeliveryMode();
fail("Expected exception not thrown");
}
catch (javax.jms.IllegalStateException e)
{
// PASS
}
}
示例12: testUnidentifiedProducer
import javax.jms.TopicSession; //導入方法依賴的package包/類
public void testUnidentifiedProducer() throws Exception
{
AMQConnection con = (AMQConnection) getConnection("guest", "guest");
AMQTopic topic = new AMQTopic(con,"MyTopic");
TopicSession session1 = con.createTopicSession(false, AMQSession.NO_ACKNOWLEDGE);
TopicPublisher publisher = session1.createPublisher(null);
MessageConsumer consumer1 = session1.createConsumer(topic);
con.start();
publisher.publish(topic, session1.createTextMessage("Hello"));
TextMessage m = (TextMessage) consumer1.receive(2000);
assertNotNull(m);
try
{
publisher.publish(session1.createTextMessage("Goodbye"));
fail("Did not throw UnsupportedOperationException");
}
catch (UnsupportedOperationException e)
{
// PASS
}
con.close();
}
示例13: testSendingSameMessage
import javax.jms.TopicSession; //導入方法依賴的package包/類
public void testSendingSameMessage() throws Exception
{
AMQConnection conn = (AMQConnection) getConnection("guest", "guest");
TopicSession session = conn.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
TemporaryTopic topic = session.createTemporaryTopic();
assertNotNull(topic);
TopicPublisher producer = session.createPublisher(topic);
MessageConsumer consumer = session.createConsumer(topic);
conn.start();
TextMessage sentMessage = session.createTextMessage("Test Message");
producer.send(sentMessage);
session.commit();
TextMessage receivedMessage = (TextMessage) consumer.receive(2000);
assertNotNull(receivedMessage);
assertEquals(sentMessage.getText(), receivedMessage.getText());
producer.send(sentMessage);
session.commit();
receivedMessage = (TextMessage) consumer.receive(2000);
assertNotNull(receivedMessage);
assertEquals(sentMessage.getText(), receivedMessage.getText());
session.commit();
conn.close();
}
示例14: 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();
}
示例15: publishTextMsg2Topic
import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
* Product message for assigned topic.
*
* @param uri
* e.g.: tcp://3CNL12096:61616
* @param queueName
* name of queue
* @throws JMSException
*/
public static void publishTextMsg2Topic(String uri, String topicName, String text) throws JMSException {
TopicConnectionFactory connectionFactory = null;
TopicConnection connection = null;
TopicSession session = null;
TopicPublisher tp = null;
try {
connectionFactory = new ActiveMQConnectionFactory(uri);
connection = connectionFactory.createTopicConnection();
connection.start();
session = connection.createTopicSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
tp = session.createPublisher(session.createTopic(topicName));
tp.setDeliveryMode(DeliveryMode.PERSISTENT);
tp.publish(session.createTextMessage(text));
session.commit();
} finally {
closeQuietly(tp);
closeQuietly(session);
closeQuietly(connection);
}
}