當前位置: 首頁>>代碼示例>>Java>>正文


Java TopicPublisher類代碼示例

本文整理匯總了Java中javax.jms.TopicPublisher的典型用法代碼示例。如果您正苦於以下問題:Java TopicPublisher類的具體用法?Java TopicPublisher怎麽用?Java TopicPublisher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TopicPublisher類屬於javax.jms包,在下文中一共展示了TopicPublisher類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGetTopic

import javax.jms.TopicPublisher; //導入依賴的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) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:18,代碼來源:JmsPoolTopicPublisherTest.java

示例2: testSenderAndPublisherDest

import javax.jms.TopicPublisher; //導入依賴的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();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:22,代碼來源:XAConnectionPoolTest.java

示例3: publish

import javax.jms.TopicPublisher; //導入依賴的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);
		}
	}
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:30,代碼來源:BasicJMSChat.java

示例4: send

import javax.jms.TopicPublisher; //導入依賴的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);
  }
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:24,代碼來源:JmsPublisher.java

示例5: setUp

import javax.jms.TopicPublisher; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
  eventBus = new SimpleEventBus();
  cut = new JmsPublisher(eventBus);
  connectionFactory = mock(TopicConnectionFactory.class);
  publisher = mock(TopicPublisher.class);
  topic = mock(Topic.class);
  converter = mock(JmsMessageConverter.class);
  cut.setConnectionFactory(connectionFactory);
  cut.setTopic(topic);
  cut.setTransacted(true);
  cut.setMessageConverter(converter);
  cut.setPersistent(false);
  cut.postConstruct();
  cut.start();
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:17,代碼來源:JmsPublisherTest.java

示例6: closeProducer

import javax.jms.TopicPublisher; //導入依賴的package包/類
/**
 * Close a JMS {@link MessageProducer}.
 * @param messageProducer JMS Message Producer that needs to be closed.
 * @throws JMSException if an error occurs while closing the producer.
 */
public void closeProducer(MessageProducer messageProducer) throws JMSException {
    if (messageProducer != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Closing a JMS Message Producer of: " + this.connectionFactoryString);
        }
        if ((JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec)) || (JMSConstants.JMS_SPEC_VERSION_2_0
                .equals(jmsSpec))) {
            messageProducer.close();
        } else {
            if (JMSConstants.JMSDestinationType.QUEUE.equals(this.destinationType)) {
                ((QueueSender) messageProducer).close();
            } else {
                ((TopicPublisher) messageProducer).close();
            }
        }
    }
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:23,代碼來源:JMSConnectionResourceFactory.java

示例7: testSendAndReceiveOnTopic

import javax.jms.TopicPublisher; //導入依賴的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();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:JMSTopicConsumerTest.java

示例8: testPersistentMessagesForTopicDropped

import javax.jms.TopicPublisher; //導入依賴的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);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:19,代碼來源:AcknowledgementTest.java

示例9: testPersistentMessagesForTopicDropped2

import javax.jms.TopicPublisher; //導入依賴的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);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:29,代碼來源:AcknowledgementTest.java

示例10: publish

import javax.jms.TopicPublisher; //導入依賴的package包/類
/**
 * Publish message
 *
 * @param message The message
 * @throws JMSException Thrown if an error occurs
 */
@Override
public void publish(final Message message) throws JMSException {
   session.lock();
   try {
      if (ActiveMQRATopicPublisher.trace) {
         ActiveMQRALogger.LOGGER.trace("send " + this + " message=" + message);
      }

      checkState();

      ((TopicPublisher) producer).publish(message);

      if (ActiveMQRATopicPublisher.trace) {
         ActiveMQRALogger.LOGGER.trace("sent " + this + " result=" + message);
      }
   } finally {
      session.unlock();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:ActiveMQRATopicPublisher.java

示例11: createPublisher

import javax.jms.TopicPublisher; //導入依賴的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();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:32,代碼來源:ActiveMQRASession.java

示例12: sendResponse

import javax.jms.TopicPublisher; //導入依賴的package包/類
/**
 * Overrides the superclass method to use the JMS 1.0.2 API to send a response.
 * <p>Uses the JMS pub-sub API if the given destination is a topic,
 * else uses the JMS queue API.
 */
protected void sendResponse(Session session, Destination destination, Message response) throws JMSException {
	MessageProducer producer = null;
	try {
		if (destination instanceof Topic) {
			producer = ((TopicSession) session).createPublisher((Topic) destination);
			postProcessProducer(producer, response);
			((TopicPublisher) producer).publish(response);
		}
		else {
			producer = ((QueueSession) session).createSender((Queue) destination);
			postProcessProducer(producer, response);
			((QueueSender) producer).send(response);
		}
	}
	finally {
		JmsUtils.closeMessageProducer(producer);
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:24,代碼來源:MessageListenerAdapter102.java

示例13: doSend

import javax.jms.TopicPublisher; //導入依賴的package包/類
/**
 * This implementation overrides the superclass method to use JMS 1.0.2 API.
 */
protected void doSend(MessageProducer producer, Message message) throws JMSException {
	if (isPubSubDomain()) {
		if (isExplicitQosEnabled()) {
			((TopicPublisher) producer).publish(message, getDeliveryMode(), getPriority(), getTimeToLive());
		}
		else {
			((TopicPublisher) producer).publish(message);
		}
	}
	else {
		if (isExplicitQosEnabled()) {
			((QueueSender) producer).send(message, getDeliveryMode(), getPriority(), getTimeToLive());
		}
		else {
			((QueueSender) producer).send(message);
		}
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:22,代碼來源:JmsTemplate102.java

示例14: testTopicProducerCallback

import javax.jms.TopicPublisher; //導入依賴的package包/類
/**
 * Test the execute(ProducerCallback) using a topic.
 */
@Test
public void testTopicProducerCallback() throws Exception {
	JmsTemplate102 template = createTemplate();
	template.setPubSubDomain(true);
	template.setConnectionFactory(topicConnectionFactory);
	template.afterPropertiesSet();

	TopicPublisher topicPublisher = mock(TopicPublisher.class);

	given(topicSession.createPublisher(null)).willReturn(topicPublisher);
	given(topicPublisher.getPriority()).willReturn(4);

	template.execute(new ProducerCallback() {
		@Override
		public Object doInJms(Session session, MessageProducer producer) throws JMSException {
			session.getTransacted();
			producer.getPriority();
			return null;
		}
	});

	verify(topicPublisher).close();
	verify(topicSession).close();
	verify(topicConnection).close();
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:29,代碼來源:JmsTemplate102Tests.java

示例15: createPublisher

import javax.jms.TopicPublisher; //導入依賴的package包/類
@Override
public TopicPublisher createPublisher(Topic topic) throws JMSException
   {
   	externalAccessLock.readLock().lock();
   	try
	{
        checkNotClosed();
        LocalTopicPublisher publisher = new LocalTopicPublisher(this,topic,idProvider.createID());
        registerProducer(publisher);
        return publisher;
	}
   	finally
   	{
   		externalAccessLock.readLock().unlock();
   	}
   }
 
開發者ID:timewalker74,項目名稱:ffmq,代碼行數:17,代碼來源:LocalTopicSession.java


注:本文中的javax.jms.TopicPublisher類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。