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


Java ActiveMQConnection.createSession方法代码示例

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


在下文中一共展示了ActiveMQConnection.createSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testZeroPrefetchConsumerIsAborted

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
@Test
public void testZeroPrefetchConsumerIsAborted() throws Exception {
   strategy.setMaxTimeSinceLastAck(2000); // Make it shorter

   ActiveMQConnection conn = (ActiveMQConnection) createConnectionFactory().createConnection();
   conn.setExceptionListener(this);
   connections.add(conn);

   Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   final MessageConsumer consumer = sess.createConsumer(destination);
   assertNotNull(consumer);
   conn.start();
   startProducers(destination, 20);

   Message message = consumer.receive(5000);
   assertNotNull(message);

   TimeUnit.SECONDS.sleep(15);

   try {
      consumer.receive(5000);
      fail("Slow consumer not aborted.");
   } catch (Exception ex) {
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:AbortSlowAckConsumer0Test.java

示例2: startSession

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
static Session startSession(ActiveMQConnection connection) {
    try {
        return connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
    } catch (JMSException ex) {
        throw new MessageQueueException("Could not start ActiveMQ session ", ex);
    }
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:8,代码来源:ActiveMqUtils.java

示例3: startListener

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private void startListener(MessageHandler handler) {
    log.debug("Starting listener...");
    try {
        ActiveMQConnection connection = ActiveMqUtils.openConnection(user, password, url);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(queueInput);
        MessageConsumer consumer = session.createConsumer(queue);
        consumer.setMessageListener(message -> handleMessage(handler, message, session));
        log.debug("Listening to {}", queueInput);
    } catch (Exception e) {
        log.error("Error starting listening to queue {}", queueInput, e);
    }
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:14,代码来源:ActiveMqListener.java

示例4: testSecurityContextClearedOnPurge

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
public void testSecurityContextClearedOnPurge() throws Exception {

        connection.close();
        ActiveMQConnectionFactory tcpFactory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
        ActiveMQConnection conn = (ActiveMQConnection) tcpFactory.createConnection("user", "password");
        Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        conn.start();

        final int numDests = broker.getRegionBroker().getDestinations().length;
        for (int i=0; i<10; i++) {
            MessageProducer p = sess.createProducer(new ActiveMQQueue("USERS.PURGE." + i));
            p.close();
        }

        assertTrue("dests are purged", Wait.waitFor(new Wait.Condition() {
            @Override
            public boolean isSatisified() throws Exception {
                LOG.info("dests, orig: " + numDests + ", now: "+ broker.getRegionBroker().getDestinations().length);
                return (numDests + 1) == broker.getRegionBroker().getDestinations().length;
            }
        }));

        // verify removed from connection security context
        TransportConnection brokerConnection = broker.getTransportConnectors().get(0).getConnections().get(0);
        TransportConnectionState transportConnectionState = brokerConnection.lookupConnectionState(conn.getConnectionInfo().getConnectionId());
        assertEquals("no destinations", 0, transportConnectionState.getContext().getSecurityContext().getAuthorizedWriteDests().size());
    }
 
开发者ID:ctytgat,项目名称:amq-jdbc-security,代码行数:28,代码来源:JdbcAuthenticationPluginTest.java

示例5: test2ndPublisherWithProducerWindowSendConnectionThatIsBlocked

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
@Test
public void test2ndPublisherWithProducerWindowSendConnectionThatIsBlocked() throws Exception {
   factory.setProducerWindowSize(1024 * 64);
   flowControlConnection = (ActiveMQConnection) factory.createConnection();
   flowControlConnection.start();

   Session session = flowControlConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   MessageConsumer consumer = session.createConsumer(queueB);

   // Test sending to Queue A
   // 1 few sends should not block until the producer window is used up.
   fillQueue(queueA);

   // Test sending to Queue B it should not block since the connection
   // should not be blocked.
   CountDownLatch pubishDoneToQeueuB = asyncSendTo(queueB, "Message 1");
   assertTrue(pubishDoneToQeueuB.await(2, TimeUnit.SECONDS));

   TextMessage msg = (TextMessage) consumer.receive();
   assertEquals("Message 1", msg.getText());
   msg.acknowledge();

   pubishDoneToQeueuB = asyncSendTo(queueB, "Message 2");
   assertTrue(pubishDoneToQeueuB.await(2, TimeUnit.SECONDS));

   msg = (TextMessage) consumer.receive();
   assertEquals("Message 2", msg.getText());
   msg.acknowledge();

   consumer.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:32,代码来源:ProducerFlowControlTest.java

示例6: test2ndPublisherWithSyncSendConnectionThatIsBlocked

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
@Test
public void test2ndPublisherWithSyncSendConnectionThatIsBlocked() throws Exception {
   factory.setAlwaysSyncSend(true);
   flowControlConnection = (ActiveMQConnection) factory.createConnection();
   flowControlConnection.start();

   Session session = flowControlConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   MessageConsumer consumer = session.createConsumer(queueB);

   // Test sending to Queue A
   // 1st send should not block. But the rest will.
   fillQueue(queueA);

   // Test sending to Queue B it should not block.
   CountDownLatch pubishDoneToQeueuB = asyncSendTo(queueB, "Message 1");
   assertTrue(pubishDoneToQeueuB.await(2, TimeUnit.SECONDS));

   TextMessage msg = (TextMessage) consumer.receive();
   assertEquals("Message 1", msg.getText());
   msg.acknowledge();

   pubishDoneToQeueuB = asyncSendTo(queueB, "Message 2");
   assertTrue(pubishDoneToQeueuB.await(2, TimeUnit.SECONDS));

   msg = (TextMessage) consumer.receive();
   assertEquals("Message 2", msg.getText());
   msg.acknowledge();
   consumer.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:30,代码来源:ProducerFlowControlTest.java

示例7: testSecurityContextClearedOnPurge

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
public void testSecurityContextClearedOnPurge() throws Exception {

      connection.close();
      ActiveMQConnectionFactory tcpFactory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
      ActiveMQConnection conn = (ActiveMQConnection) tcpFactory.createConnection("user", "password");
      Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      conn.start();

      final int numDests = broker.getRegionBroker().getDestinations().length;
      for (int i = 0; i < 10; i++) {
         MessageProducer p = sess.createProducer(new ActiveMQQueue("USERS.PURGE." + i));
         p.close();
      }

      assertTrue("dests are purged", Wait.waitFor(new Wait.Condition() {
         @Override
         public boolean isSatisified() throws Exception {
            LOG.info("dests, orig: " + numDests + ", now: " + broker.getRegionBroker().getDestinations().length);
            return (numDests + 1) == broker.getRegionBroker().getDestinations().length;
         }
      }));

      // verify removed from connection security context
      TransportConnection brokerConnection = broker.getTransportConnectors().get(0).getConnections().get(0);
      TransportConnectionState transportConnectionState = brokerConnection.lookupConnectionState(conn.getConnectionInfo().getConnectionId());
      assertEquals("no destinations", 0, transportConnectionState.getContext().getSecurityContext().getAuthorizedWriteDests().size());
   }
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:28,代码来源:SimpleAuthenticationPluginTest.java

示例8: sendTestObjectMessage

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private void sendTestObjectMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
   ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = session.createProducer(queue);
   ObjectMessage objectMessage = session.createObjectMessage();

   objectMessage.setObject(TEXT);

   producer.send(objectMessage);
   connection.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:12,代码来源:MessageCompressionTest.java

示例9: sendMessage

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private void sendMessage(int timeToLive) throws Exception {
   ActiveMQConnection producerConnection = (ActiveMQConnection) createConnection();
   producerConnection.start();
   Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = producerSession.createProducer(destination);
   if (timeToLive > 0) {
      producer.setTimeToLive(timeToLive);
   }
   Message message = producerSession.createMessage();
   message.setStringProperty("data", data);
   producer.send(message);
   producerConnection.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:14,代码来源:BrokerRedeliveryTest.java

示例10: receiveTestObjectMessage

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private ActiveMQObjectMessage receiveTestObjectMessage(ActiveMQConnectionFactory factory) throws JMSException {
   ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer = session.createConsumer(queue);
   ActiveMQObjectMessage rc = (ActiveMQObjectMessage) consumer.receive();
   connection.close();
   return rc;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:10,代码来源:MessageCompressionTest.java

示例11: testIdleConsumerCanBeAborted

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
@Test
public void testIdleConsumerCanBeAborted() throws Exception {
   strategy.setIgnoreIdleConsumers(false);
   strategy.setMaxTimeSinceLastAck(2000); // Make it shorter

   ActiveMQConnection conn = (ActiveMQConnection) createConnectionFactory().createConnection();
   conn.setExceptionListener(this);
   connections.add(conn);

   Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   final MessageConsumer consumer = sess.createConsumer(destination);
   assertNotNull(consumer);
   conn.start();
   startProducers(destination, 1);

   Message message = consumer.receive(5000);
   assertNotNull(message);
   message.acknowledge();

   // Consumer needs to be closed before the receive call.
   TimeUnit.SECONDS.sleep(15);

   try {
      consumer.receive(5000);
      fail("Idle consumer not aborted.");
   } catch (Exception ex) {
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:29,代码来源:AbortSlowAckConsumer0Test.java

示例12: receiveTestMapMessage

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private ActiveMQMapMessage receiveTestMapMessage(ActiveMQConnectionFactory factory) throws JMSException {
   ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer = session.createConsumer(queue);
   ActiveMQMapMessage rc = (ActiveMQMapMessage) consumer.receive();
   connection.close();
   return rc;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:10,代码来源:MessageCompressionTest.java

示例13: createClients

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
protected void createClients(int numOfClients) throws Exception {
   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(clientUrl);
   for (int i = 0; i < numOfClients; i++) {
      ActiveMQConnection c = (ActiveMQConnection) factory.createConnection();
      c.start();
      Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue queue = s.createQueue(getClass().getName());
      MessageConsumer consumer = s.createConsumer(queue);
      connections.add(c);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:12,代码来源:FailoverComplexClusterTest.java

示例14: receiveTestStreamMessage

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private ActiveMQStreamMessage receiveTestStreamMessage(ActiveMQConnectionFactory factory) throws JMSException {
   ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer = session.createConsumer(queue);
   ActiveMQStreamMessage rc = (ActiveMQStreamMessage) consumer.receive();
   connection.close();
   return rc;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:10,代码来源:MessageCompressionTest.java

示例15: Consumer

import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
public Consumer(String brokerURL, String interest, String clientId) throws JMSException {
   factory = new ActiveMQConnectionFactory(brokerURL);
   connection = (ActiveMQConnection) factory.createConnection();
   connection.setClientID(clientId);
   connection.start();
   connection.getPrefetchPolicy().setAll(15);
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Destination destination = session.createTopic(interest);
   messageConsumer = session.createDurableSubscriber((Topic) destination, "MyDurableTopic");
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:11,代码来源:DurableSubscriberNonPersistentMessageTest.java


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