• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ClientConsumer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.activemq.artemis.api.core.client.ClientConsumer的典型用法代码示例。如果您正苦于以下问题:Java ClientConsumer类的具体用法?Java ClientConsumer怎么用?Java ClientConsumer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClientConsumer类属于org.apache.activemq.artemis.api.core.client包,在下文中一共展示了ClientConsumer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: newTask

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
private DequeueTask<ArtemisMessage, String> newTask(String sentData)
        throws Exception {
    CoreQueueConfiguration q = new CoreQueueConfiguration();
    q.setName("q");
    ClientSession sesh = mock(ClientSession.class);
    ClientConsumer receiver = mock(ClientConsumer.class);
    when(sesh.createConsumer(q.getName(), false)).thenReturn(receiver);
    
    QConnector<ArtemisMessage> connector = new ArtemisQConnector(q, sesh);
    DequeueTask<ArtemisMessage, String> task =
            new DequeueTask<>(connector, this, deserializer(sentData), true);

    verify(receiver).setMessageHandler(any());
    
    return task;
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:17,代码来源:DequeueTaskTest.java


示例2: testBasicSendToNoQueue

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Test
public void testBasicSendToNoQueue() throws Exception {
   SimpleString qName = new SimpleString("q1");
   AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1);
   server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
   clientSession.createQueue(qName, qName, null, false);
   ClientProducer producer = clientSession.createProducer(qName);
   producer.send(createTextMessage(clientSession, "heyho!"));
   clientSession.start();
   ClientConsumer clientConsumer = clientSession.createConsumer(qName);
   ClientMessage m = clientConsumer.receive(500);
   m.acknowledge();
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
   // force a cancel
   clientSession.rollback();
   m = clientConsumer.receiveImmediate();
   Assert.assertNull(m);
   clientConsumer.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:21,代码来源:DeadLetterAddressTest.java


示例3: testSimpleSendNoXAJMSContext

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Test
public void testSimpleSendNoXAJMSContext() throws Exception {
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);

   try (ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession();
        ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
        JMSContext jmsctx = qraConnectionFactory.createContext();
   ) {
      session.start();
      // These next 4 lines could be written in a single line however it makes difficult for debugging
      JMSProducer producer = jmsctx.createProducer();
      producer.setProperty("strvalue", "hello");
      TextMessage msgsend = jmsctx.createTextMessage("hello");
      producer.send(q, msgsend);

      ClientMessage msg = consVerify.receive(1000);
      assertNotNull(msg);
      assertEquals("hello", msg.getStringProperty("strvalue"));
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:OutgoingConnectionJTATest.java


示例4: testSimpleSendNoXAJMS1

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Test
public void testSimpleSendNoXAJMS1() throws Exception {
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
   try (ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession();
        ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
        Connection conn = qraConnectionFactory.createConnection();
   ) {
      Session jmsSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      session.start();
      MessageProducer producer = jmsSess.createProducer(q);
      // These next 4 lines could be written in a single line however it makes difficult for debugging
      TextMessage msgsend = jmsSess.createTextMessage("hello");
      msgsend.setStringProperty("strvalue", "hello");
      producer.send(msgsend);

      ClientMessage msg = consVerify.receive(1000);
      assertNotNull(msg);
      assertEquals("hello", msg.getStringProperty("strvalue"));
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:OutgoingConnectionNoJTATest.java


示例5: individualAcknowledge

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Override
public void individualAcknowledge(final ClientConsumer consumer, final Message message) throws ActiveMQException {
   // if we're pre-acknowledging then we don't need to do anything
   if (preAcknowledge) {
      return;
   }

   checkClosed();

   startCall();
   try {

      sessionContext.sendACK(true, blockOnAcknowledge, consumer, message);
   } finally {
      endCall();
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:18,代码来源:ClientSessionImpl.java


示例6: testWildcardRoutingHashAndStar

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Test
public void testWildcardRoutingHashAndStar() throws Exception {
   SimpleString addressAB = new SimpleString("a.b.c");
   SimpleString addressAC = new SimpleString("a.c");
   SimpleString address = new SimpleString("#.b.*");
   SimpleString queueName1 = new SimpleString("Q1");
   SimpleString queueName2 = new SimpleString("Q2");
   SimpleString queueName = new SimpleString("Q");
   clientSession.createQueue(addressAB, queueName1, null, false);
   clientSession.createQueue(addressAC, queueName2, null, false);
   clientSession.createQueue(address, queueName, null, false);
   ClientProducer producer = clientSession.createProducer(addressAB);
   ClientProducer producer2 = clientSession.createProducer(addressAC);
   ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
   clientSession.start();
   producer.send(createTextMessage(clientSession, "m1"));
   producer2.send(createTextMessage(clientSession, "m2"));
   ClientMessage m = clientConsumer.receive(500);
   Assert.assertNotNull(m);
   Assert.assertEquals("m1", m.getBodyBuffer().readString());
   m.acknowledge();
   m = clientConsumer.receiveImmediate();
   Assert.assertNull(m);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:25,代码来源:WildCardRoutingTest.java


示例7: testReceiveThrowsExceptionWhenHandlerSet

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Test
public void testReceiveThrowsExceptionWhenHandlerSet() throws Exception {

   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession(false, true, true);
   session.createQueue(addressA, queueA, false);
   ClientConsumer cc = session.createConsumer(queueA);
   session.start();
   cc.setMessageHandler(new MessageHandler() {
      @Override
      public void onMessage(final ClientMessage message) {
      }
   });
   try {
      cc.receive();
      Assert.fail("should throw exception");
   } catch (ActiveMQIllegalStateException ise) {
      //ok
   } catch (ActiveMQException e) {
      Assert.fail("Invalid Exception type:" + e.getType());
   }
   session.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:24,代码来源:ReceiveTest.java


示例8: checkUserReceiveNoSend

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
private void checkUserReceiveNoSend(final String queue,
                                    final ClientSession connection,
                                    final ClientSession sendingConn) throws Exception {
   connection.start();
   try {
      ClientProducer prod = connection.createProducer(queue);
      ClientMessage m = connection.createMessage(false);
      try {
         prod.send(m);
         Assert.fail("should throw exception");
      } catch (ActiveMQException e) {
         // pass
      }

      prod = sendingConn.createProducer(queue);
      prod.send(m);
      ClientConsumer con = connection.createConsumer(queue);
      ClientMessage rec = con.receive(1000);
      Assert.assertNotNull(rec);
      rec.acknowledge();
   } finally {
      connection.stop();
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:25,代码来源:SecurityTest.java


示例9: testClearListener

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Test
public void testClearListener() throws Exception {
   ClientSessionFactory sf = createSessionFactory(locator);

   ClientSession session = sf.createSession(false, true, true);
   session.start();

   ClientConsumer consumer = session.createConsumer(QUEUE);

   consumer.setMessageHandler(new MessageHandler() {
      @Override
      public void onMessage(final ClientMessage msg) {
      }
   });

   consumer.setMessageHandler(null);
   consumer.receiveImmediate();

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


示例10: verifyMessageOnServer

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
/**
 * @throws Exception
 */
private void verifyMessageOnServer(final int server, final int numberOfMessages) throws Exception {
   ServerLocator backupLocator = createInVMLocator(server);
   ClientSessionFactory factorybkp = addSessionFactory(createSessionFactory(backupLocator));
   ClientSession sessionbkp = factorybkp.createSession(false, false);
   sessionbkp.start();
   ClientConsumer consumerbkp = sessionbkp.createConsumer(ADDRESS);
   for (int i = 0; i < numberOfMessages; i++) {
      ClientMessage msg = consumerbkp.receive(1000);
      assertNotNull(msg);
      msg.acknowledge();
      sessionbkp.commit();
   }
   sessionbkp.close();
   factorybkp.close();
   backupLocator.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:20,代码来源:FailoverListenerTest.java


示例11: testConsumeFromFormat

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Test
public void testConsumeFromFormat() throws Exception {
   ActiveMQServer server = createServer(true);

   DecodeJournal.importJournal(server.getConfiguration().getJournalLocation().getAbsolutePath(), "activemq-data", "amq", 2, 102400, new StringReader(journalFile));
   DecodeJournal.importJournal(server.getConfiguration().getBindingsLocation().getAbsolutePath(), "activemq-bindings", "bindings", 2, 1048576, new StringReader(bindingsFile));
   server.start();

   ServerLocator locator = createInVMNonHALocator();
   ClientSessionFactory factory = createSessionFactory(locator);
   ClientSession session = factory.createSession();
   session.start();

   ClientConsumer consumer = session.createConsumer("A1");
   for (int i = 0; i < 10; i++) {
      ClientMessage msg = consumer.receive(5000);
      assertNotNull(msg);
      msg.acknowledge();
      assertEquals(i, msg.getIntProperty("key").intValue());
   }

   session.commit();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:24,代码来源:ExportFormatTest.java


示例12: testLargeMessage

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Test
public void testLargeMessage() throws Exception {
   ClientProducer producer = clientSessionTxReceives.createProducer(address);
   ClientConsumer consumer = clientSessionTxReceives.createConsumer(qName1);
   SimpleString rh = new SimpleString("SMID1");

   for (int i = 0; i < 50; i++) {
      ClientMessage message = clientSession.createMessage(true);
      message.setBodyInputStream(createFakeLargeStream(300 * 1024));
      message.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
      producer.send(message);
      clientSession.commit();
   }
   clientSessionTxReceives.start();
   ClientMessage m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertNull(consumer.receiveImmediate());
   clientSessionTxReceives.commit();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:21,代码来源:LVQTest.java


示例13: readMessages

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
private int readMessages(final ClientSession session,
                         final ClientConsumer consumer,
                         final SimpleString queue) throws ActiveMQException {
   session.start();
   int msgs = 0;

   ClientMessage msg = null;
   do {
      msg = consumer.receive(1000);
      if (msg != null) {
         msg.acknowledge();
         if (++msgs % 10000 == 0) {
            System.out.println("received " + msgs);
            session.commit();

         }
      }
   }
   while (msg != null);

   session.commit();

   return msgs;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:25,代码来源:PageStressTest.java


示例14: drainQueue

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
/**
 * @param numberOfMessagesExpected
 * @param queue
 * @throws ActiveMQException
 */
private void drainQueue(final int numberOfMessagesExpected, final SimpleString queue) throws ActiveMQException {
   ClientSession sess = sf.createSession(true, true);

   ClientConsumer consumer = sess.createConsumer(queue);

   sess.start();

   for (int i = 0; i < numberOfMessagesExpected; i++) {
      ClientMessage msg = consumer.receive(5000);
      Assert.assertNotNull(msg);

      if (i % 100 == 0) {
         // System.out.println("Received #" + i + "  on thread after start");
      }
      msg.acknowledge();
   }

   Assert.assertNull(consumer.receiveImmediate());

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


示例15: newConsumer

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Override
public QConsumer<ArtemisMessage> newConsumer(
        BiConsumerE<ArtemisMessage, InputStream> messageHandler)
        throws ActiveMQException {
    ClientConsumer consumer =
            session.createConsumer(config.getName(), false);
    return new ArtemisQConsumer(consumer, messageHandler);
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:9,代码来源:ArtemisQConnector.java


示例16: newBrowser

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Override
public QConsumer<ArtemisMessage> newBrowser(
        BiConsumerE<ArtemisMessage, InputStream> messageHandler)
        throws ActiveMQException {
    ClientConsumer consumer =
            session.createConsumer(config.getName(), true);
    return new ArtemisQConsumer(consumer, messageHandler);
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:9,代码来源:ArtemisQConnector.java


示例17: ArtemisQConsumer

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
/**
 * Creates a new instance.
 * @param consumer the Artemis queue consumer.
 * @param messageHandler processes messages received by the consumer.
 * @throws NullPointerException if any argument is {@code null}.
 * @throws ActiveMQException if the message handler couldn't be connected
 * to the consumer.
 */
public ArtemisQConsumer(
        ClientConsumer consumer,
        BiConsumerE<ArtemisMessage, InputStream> messageHandler)
        throws ActiveMQException {
    requireNonNull(consumer, "consumer");
    requireNonNull(messageHandler, "messageHandler");

    this.consumer = consumer;
    this.messageHandler = messageHandler;

    consumer.setMessageHandler(this);
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:21,代码来源:ArtemisQConsumer.java


示例18: setup

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Before
public void setup() throws ActiveMQException {
    mockConfig = mock(CoreQueueConfiguration.class);
    mockSession = mock(ClientSession.class);
    target = new ArtemisQConnector(mockConfig, mockSession);

    when(mockSession.createConsumer(anyString(), anyBoolean()))
            .thenReturn(mock(ClientConsumer.class));
    when(mockSession.createProducer(anyString()))
            .thenReturn(mock(ClientProducer.class));
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:12,代码来源:ArtemisQConnectorTest.java


示例19: setup

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Before
public void setup() throws ActiveMQException {
    mockConsumer = mock(ClientConsumer.class);
    target = new ArtemisQConsumer(mockConsumer, this::handleMessage);
    receivedMessage = null;
    receivedBody = null;
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:8,代码来源:ArtemisQConsumerTest.java


示例20: testMulticastQueues

import org.apache.activemq.artemis.api.core.client.ClientConsumer; //导入依赖的package包/类
@Test
public void testMulticastQueues() throws Exception {
   server.createQueue(multicastAddress, RoutingType.MULTICAST, multicastQ1, null, true, false, -1, false, true);
   server.createQueue(multicastAddress, RoutingType.MULTICAST, multicastQ2, null, true, false, -1, false, true);
   server.createQueue(multicastAddress, RoutingType.MULTICAST, multicastQ3, null, true, false, -1, false, true);

   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession();
   session.start();

   //send 3 messages
   ClientProducer producer = session.createProducer(multicastAddress);
   sendMessages(session, producer, 1);

   ClientConsumer consumer1 = session.createConsumer(toFullQN(multicastAddress, multicastQ1));
   ClientConsumer consumer2 = session.createConsumer(toFullQN(multicastAddress, multicastQ2));
   ClientConsumer consumer3 = session.createConsumer(toFullQN(multicastAddress, multicastQ3));
   session.start();

   //each consumer receives one
   ClientMessage m = consumer1.receive(2000);
   assertNotNull(m);
   m.acknowledge();
   m = consumer2.receive(2000);
   assertNotNull(m);
   m.acknowledge();
   m = consumer3.receive(2000);
   assertNotNull(m);
   m.acknowledge();

   session.commit();
   //queues are empty now
   for (SimpleString q : new SimpleString[]{multicastQ1, multicastQ2, multicastQ3}) {
      QueueQueryResult query = server.queueQuery(toFullQN(multicastAddress, q));
      assertTrue(query.isExists());
      assertEquals(multicastAddress, query.getAddress());
      assertEquals(toFullQN(multicastAddress, q), query.getName());
      assertEquals(0, query.getMessageCount());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:41,代码来源:FullQualifiedQueueTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SimplePdfExporterConfiguration类代码示例发布时间:2022-05-23
下一篇:
Java SchemaReader类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap