当前位置: 首页>>代码示例>>Java>>正文


Java TopicPublisher.close方法代码示例

本文整理汇总了Java中javax.jms.TopicPublisher.close方法的典型用法代码示例。如果您正苦于以下问题:Java TopicPublisher.close方法的具体用法?Java TopicPublisher.close怎么用?Java TopicPublisher.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jms.TopicPublisher的用法示例。


在下文中一共展示了TopicPublisher.close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: closeResources

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
private static void closeResources(TopicConnection pConn, TopicSession pSession,
        TopicPublisher pPublisher) throws JMSException {
    if (pPublisher != null) {
        pPublisher.close();
    }
    if (pSession != null) {
        pSession.close();
    }
    if (pConn != null) {
        pConn.close();
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:13,代码来源:JMSServices.java

示例4: testSendAndReceiveOnAutoCreatedTopic

import javax.jms.TopicPublisher; //导入方法依赖的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();
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:40,代码来源:JMSTopicConsumerTest.java

示例5: testSendWithMultipleReceiversOnTopic

import javax.jms.TopicPublisher; //导入方法依赖的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();
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:33,代码来源:JMSTopicConsumerTest.java

示例6: run

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
@Override
public void run()
   {
       try
       {
           TopicPublisher publisher = getSession().createPublisher(topic);
           notifyStartup();
           
           startSynchro.waitFor();
           
           for (int n = 0 ; n < messageCount ; n++)
           {
               variableWait();
               
               int msgPriority = (priority != -1) ? priority : random.nextInt(10);
               
               Message message = msgFactory.createDummyMessage(messageSize);
               publisher.publish(message, deliveryMode, msgPriority, timeToLive);
               if (transacted)
                   getSession().commit();
           }
           
           publisher.close();
           //System.out.println(getName()+" thread complete ("+messageCount+" messages sent)");
       }
       catch (Throwable e)
       {
           inError = true;
           e.printStackTrace();
       }
   }
 
开发者ID:timewalker74,项目名称:ffmq,代码行数:32,代码来源:TopicPublisherThread.java

示例7: testMultipleCloseCallsNoErrors

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
@Test(timeout = 10000)
public void testMultipleCloseCallsNoErrors() throws Exception {
    Topic topic = session.createTopic(getTestName());
    TopicPublisher publisher = session.createPublisher(topic);
    publisher.close();
    publisher.close();
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:8,代码来源:JmsTopicPublisherTest.java

示例8: sendByTopic

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
protected String sendByTopic(TopicSession session, Topic destination,
		Message message) throws NamingException, JMSException {
	TopicPublisher tps = session.createPublisher(destination);
	tps.publish(message);
	tps.close();
	return message.getJMSMessageID();
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:8,代码来源:JMSFacade.java

示例9: close

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
private void close(TopicPublisher publisher) {
    if (publisher != null) {
        try {
            publisher.close();
        } catch (JMSException e) {
            LOG.error("Couldn't close TopicPublisher", e);
        }
    }
}
 
开发者ID:NCIP,项目名称:caarray,代码行数:10,代码来源:JobMessageSenderImpl.java

示例10: testDurSubRestoredAfterNonPersistentMessageSent

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
/**
 * test strategy:
 * create and register a durable subscriber then close it
 * create a publisher and send a persistant message followed by a non persistant message
 * crash and restart the broker
 * recreate the durable subscriber and check that only the first message is received
 */
public void testDurSubRestoredAfterNonPersistentMessageSent() throws Exception
{
    if (isBrokerStorePersistent())
    {
        TopicConnectionFactory factory = getConnectionFactory();
        Topic topic = (Topic) getInitialContext().lookup(_topicName);
        //create and register a durable subscriber then close it
        TopicConnection durConnection = factory.createTopicConnection("guest", "guest");
        TopicSession durSession = durConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber durSub1 = durSession.createDurableSubscriber(topic, "dursub");
        durConnection.start();
        durSub1.close();
        durSession.close();
        durConnection.stop();

        //create a publisher and send a persistant message followed by a non persistant message
        TopicConnection pubConnection = factory.createTopicConnection("guest", "guest");
        TopicSession pubSession = pubConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicPublisher publisher = pubSession.createPublisher(topic);
        Message message = pubSession.createMessage();
        message.setIntProperty("count", 1);
        publisher.publish(message, javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY,
                          javax.jms.Message.DEFAULT_TIME_TO_LIVE);
        message.setIntProperty("count", 2);
        publisher.publish(message, javax.jms.DeliveryMode.NON_PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY,
                          javax.jms.Message.DEFAULT_TIME_TO_LIVE);
        publisher.close();
        pubSession.close();
        //now stop the server
        try
        {
            restartBroker();
        }
        catch (Exception e)
        {
            _logger.error("problems restarting broker: " + e);
            throw e;
        }
        //now recreate the durable subscriber and check the received messages
        factory = getConnectionFactory();
        topic = (Topic) getInitialContext().lookup(_topicName);
        TopicConnection durConnection2 = factory.createTopicConnection("guest", "guest");
        TopicSession durSession2 = durConnection2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber durSub2 = durSession2.createDurableSubscriber(topic, "dursub");
        durConnection2.start();
        Message m1 = durSub2.receive(1000);
        if (m1 == null)
        {
            assertTrue("testDurSubRestoredAfterNonPersistentMessageSent test failed. no message was returned",
                       false);
        }
        assertTrue("testDurSubRestoredAfterNonPersistentMessageSent test failed. Wrong message was returned.",
                   m1.getIntProperty("count") == 1);
        durSession2.unsubscribe("dursub");
        durConnection2.close();
    }
}
 
开发者ID:wso2,项目名称:andes,代码行数:65,代码来源:DurableSubscriberTest.java

示例11: publish

import javax.jms.TopicPublisher; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void publish(Message message, String topicName, int deliveryMode) throws EventBrokerException {

    if (isDeactivated()){
        return;
    }

    try {
        String userName = getLoggedInUserName();
        if ((userName == null) || (userName.equals(""))) {
            // use the system user name
            userName = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
        }

        TopicConnection topicConnection = getTopicConnection(userName);
        TopicSession topicSession =
                topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        String tenantDomain= EventBrokerHolder.getInstance().getTenantDomain();
        if (tenantDomain != null && (!tenantDomain.equals(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME))) {
            topicName = tenantDomain + "/" + getTopicName(topicName);
        } else {
            topicName = getTopicName(topicName);
        }

        Topic topic = topicSession.createTopic(topicName);
        //Some times we are not getting the proper topic with the required syntax, if it is not
        //appropriate we need to check and add the BURL syntax to fix the issue https://wso2.org/jira/browse/MB-185
        if (!topic.toString().startsWith("topic://amq.topic")) {
            topic = topicSession.createTopic("BURL:" + topicName);
        }
        TopicPublisher topicPublisher = topicSession.createPublisher(topic);
        topicPublisher.setDeliveryMode(deliveryMode);
        TextMessage textMessage =
                topicSession.createTextMessage(message.getMessage());

        Map<String, String> properties = message.getProperties();
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            textMessage.setStringProperty(entry.getKey(), entry.getValue());
        }

        // saving the domain to be used send with the soap header
        if (CarbonContext.getThreadLocalCarbonContext().getTenantDomain() != null){
            textMessage.setStringProperty(MultitenantConstants.TENANT_DOMAIN_HEADER_NAME,
                                        CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
        }

        topicPublisher.publish(textMessage);
        topicPublisher.close();
        topicSession.close();
        topicConnection.stop();
        topicConnection.close();
    } catch (JMSException e) {
        throw new EventBrokerException("Can not publish to topic " + topicName + " " + e.getMessage(), e);
    }
}
 
开发者ID:wso2,项目名称:carbon-business-messaging,代码行数:59,代码来源:JMSDeliveryManager.java


注:本文中的javax.jms.TopicPublisher.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。