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


Java DeliveryMode类代码示例

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


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

示例1: testSendPersistentMessage

import javax.jms.DeliveryMode; //导入依赖的package包/类
@Test
public void testSendPersistentMessage() throws Exception {
  cut.setPersistent(true);
  cut.setMessageConverter(null);
  cut.postConstruct();

  TopicConnection connection = mock(TopicConnection.class);
  when(connectionFactory.createTopicConnection()).thenReturn(connection);
  TopicSession transactionalSession = mock(TopicSession.class);

  when(connection.createTopicSession(true, Session.SESSION_TRANSACTED))
      .thenReturn(transactionalSession);
  when(transactionalSession.createPublisher(topic)).thenReturn(publisher);
  TextMessage jmsMessage = mock(TextMessage.class);
  when(transactionalSession.createTextMessage(any())).thenReturn(jmsMessage);
  ArgumentCaptor<Message> jmsMsgCapture = ArgumentCaptor.forClass(Message.class);
  doNothing().when(publisher).publish(jmsMsgCapture.capture());

  eventBus.publish(new GenericEventMessage<>("Message"));

  verify(jmsMessage).setJMSDeliveryMode(DeliveryMode.PERSISTENT);
}
 
开发者ID:sventorben,项目名称:axon-jms,代码行数:23,代码来源:JmsPublisherTest.java

示例2: send

import javax.jms.DeliveryMode; //导入依赖的package包/类
public static void send(String queueName, String text, int delayMillis) {
    EXECUTOR.submit(() -> {
        try {
            logger.info("*** artificial delay {}: {}", queueName, delayMillis);
            Thread.sleep(delayMillis);
            Connection connection = getConnection();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Destination destination = session.createQueue(queueName);
            MessageProducer producer = session.createProducer(destination);
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            TextMessage message = session.createTextMessage(text);
            producer.send(message);
            logger.info("*** sent message {}: {}", queueName, text);
            session.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
}
 
开发者ID:intuit,项目名称:karate,代码行数:20,代码来源:QueueUtils.java

示例3: publishMessage

import javax.jms.DeliveryMode; //导入依赖的package包/类
/**
 * Publish message.
 *
 * @param event the event
 * @throws JMSException the jMS exception
 */
public void publishMessage(final BasicEvent event) throws JMSException {
    
    if (System.currentTimeMillis() > lastFailureTimestamp) {
        publishedCounter.incrementAndGet();
        int shard = (int) (event.getManifestId() % poolsize);
        try {
            producers[shard].send(session -> {
                ObjectMessage message = session.createObjectMessage(event);
                message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
                message.setLongProperty("ciId", event.getCiId());
                message.setLongProperty("manifestId", event.getManifestId());
                message.setStringProperty("source", event.getSource());
                if (logger.isDebugEnabled()) {
                    logger.debug("Published: ciId:" + event.getCiId() + "; source:" + event.getSource());
                }
                return message;
            });
            lastFailureTimestamp = -1;
        } catch (JmsException exception) {
            logger.warn("There was an error sending a message. Discarding messages for " + mqConnectionThreshold + " ms");
            lastFailureTimestamp = System.currentTimeMillis() + mqConnectionThreshold;
        }
    }
}
 
开发者ID:oneops,项目名称:oneops,代码行数:31,代码来源:SensorPublisher.java

示例4: sendRequest

import javax.jms.DeliveryMode; //导入依赖的package包/类
public String sendRequest(Optional<String> routeId) {
    DetailsRequest req = new DetailsRequest(routeId.orElse("asdf"));
    try {
        TextMessage msg = context.createTextMessage(JsonMapper.serializeOrThrow(req));
        msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);

        Queue answerQ = context.createTemporaryQueue();
        msg.setJMSReplyTo(answerQ);

        context.createProducer().send(minQ, msg);

        Message response = context.createConsumer(answerQ).receive();
        if (response instanceof TextMessage) {
            return ((TextMessage) response).getText();
        }

        return "";
    } catch (JMSException e) {
        return e.getMessage();
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:22,代码来源:DetailsCaller.java

示例5: sendRequest

import javax.jms.DeliveryMode; //导入依赖的package包/类
public String sendRequest(Optional<String> routeId) {
    CompactRequest req = new CompactRequest(routeId.orElse("asdf"));
    try {
        TextMessage msg = context.createTextMessage(JsonMapper.serializeOrThrow(req));
        msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);

        Queue answerQ = context.createTemporaryQueue();
        msg.setJMSReplyTo(answerQ);

        context.createProducer().send(minQ, msg);

        Message response = context.createConsumer(answerQ).receive();
        if (response instanceof TextMessage) {
            return ((TextMessage) response).getText();
        }

        return "";
    } catch (JMSException e) {
        return e.getMessage();
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:22,代码来源:CompactCaller.java

示例6: wrapAndSendResponseInternal

import javax.jms.DeliveryMode; //导入依赖的package包/类
private void wrapAndSendResponseInternal(Message incoming, List<B> response) throws JMSException {
    String text;
    try {
        text = JsonMapper.serialize(response);
    } catch (JsonProcessingException e) {
        getLogger().warn("Failed to convert response to text. Will not send response");
        return;
    }

    getLogger().debug("Response (object): {}", response);
    getLogger().debug("Response (string): {}", text);

    TextMessage msg = getContext().createTextMessage(text);
    msg.setJMSCorrelationID(incoming.getJMSCorrelationID());

    getContext().createProducer()
                .setDisableMessageID(true)
                .setDisableMessageTimestamp(true)
                .setDeliveryMode(DeliveryMode.NON_PERSISTENT)
                .send(incoming.getJMSReplyTo(), msg);
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:22,代码来源:AbstractSharingListener.java

示例7: jmsReadOnlyPropertiesNotMapped

import javax.jms.DeliveryMode; //导入依赖的package包/类
@Test
public void jmsReadOnlyPropertiesNotMapped() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.DESTINATION, new Destination() {})
			.setHeader(JmsHeaders.DELIVERY_MODE, DeliveryMode.NON_PERSISTENT)
			.setHeader(JmsHeaders.EXPIRATION, 1000L)
			.setHeader(JmsHeaders.MESSAGE_ID, "abc-123")
			.setHeader(JmsHeaders.PRIORITY, 9)
			.setHeader(JmsHeaders.REDELIVERED, true)
			.setHeader(JmsHeaders.TIMESTAMP, System.currentTimeMillis())
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage();
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNull(jmsMessage.getJMSDestination());
	assertEquals(DeliveryMode.PERSISTENT, jmsMessage.getJMSDeliveryMode());
	assertEquals(0, jmsMessage.getJMSExpiration());
	assertNull(jmsMessage.getJMSMessageID());
	assertEquals(javax.jms.Message.DEFAULT_PRIORITY, jmsMessage.getJMSPriority());
	assertFalse(jmsMessage.getJMSRedelivered());
	assertEquals(0, jmsMessage.getJMSTimestamp());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:SimpleJmsHeaderMapperTests.java

示例8: Sender

import javax.jms.DeliveryMode; //导入依赖的package包/类
/**
 * 
 * @param queue_name : name of destination message queue
 * @param host_name : destination ip/host name
 */
public Sender(String queue_name, String host_name) {
	connectionFactory = new ActiveMQConnectionFactory(
               ActiveMQConnection.DEFAULT_USER,
               ActiveMQConnection.DEFAULT_PASSWORD,
               "tcp://" + host_name +":61616");
	
       try {
           connection = connectionFactory.createConnection();
           connection.start();
           session = connection.createSession(Boolean.TRUE,
                   Session.AUTO_ACKNOWLEDGE);      
           destination = session.createQueue(queue_name);
           producer = session.createProducer(destination);
           producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
           
       } catch (JMSException je) {
           je.printStackTrace();
       } 

}
 
开发者ID:knshen,项目名称:JSearcher,代码行数:26,代码来源:Sender.java

示例9: initializeQueue

import javax.jms.DeliveryMode; //导入依赖的package包/类
private void initializeQueue() {
    Context context = null;

    try {
        context = new InitialContext();
        final QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY_NAME);
        queueConnection = factory.createQueueConnection();
        queueConnection.start();

        final Queue queue = (Queue) context.lookup(QUEUE_NAME);

        session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        sender = session.createSender(queue);
        sender.setDeliveryMode(DeliveryMode.PERSISTENT);
    } catch (NamingException | JMSException e) {
        throw new IWSException(IWSErrors.ERROR, "Queue sender (NotificationEmailSender) initialization failed.", e);
    } finally {
        close(context);
    }
}
 
开发者ID:IWSDevelopers,项目名称:iws,代码行数:21,代码来源:NotificationEmailSender.java

示例10: publish

import javax.jms.DeliveryMode; //导入依赖的package包/类
@Override
public void publish(final String message, final String topicName, final long timeToLive) throws JMSException {
  if (topicName == null) {
    throw new NullPointerException("publish(..) method called with null queue name argument");
  }
  if (message == null) {
    throw new NullPointerException("publish(..) method called with null message argument");
  }
  if (connected) {
    final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
      final Message messageObj = session.createTextMessage(message);

      final MessageProducer producer = session.createProducer(new ActiveMQTopic(topicName));
      producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      producer.setTimeToLive(JMS_MESSAGE_TIMEOUT);
      producer.send(messageObj);
    } finally {
      session.close();
    }
  } else {
    throw new JMSException("Not currently connected: unable to send message at this time.");
  }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:25,代码来源:JmsProxyImpl.java

示例11: to

import javax.jms.DeliveryMode; //导入依赖的package包/类
@Override
public void to(JmsDestination target) {
  try {
    Connection connection = connectionFactory.createConnection();
    connection.start();

    Session session = createFunction.apply(connection);
    Destination destination = target.createDestination(session);

    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    if (this.expirationTime != null) {
      producer.setTimeToLive(this.expirationTime);
    }

    ObjectMessage message = session.createObjectMessage(object);
    producer.send(message);

    session.close();
    connection.close();
  } catch (JMSException e) {
    logger.error("Error while sending object to AMQ destination", e);
  }
}
 
开发者ID:devnull-tools,项目名称:boteco,代码行数:25,代码来源:DefaultJmsMessageConfiguration.java

示例12: produceMsg

import javax.jms.DeliveryMode; //导入依赖的package包/类
private void produceMsg() throws Exception
{
  // Create a ConnectionFactory
  ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");

  // Create a Connection
  testMeta.connection = connectionFactory.createConnection();
  testMeta.connection.start();

  // Create a Session
  testMeta.session = testMeta.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

  // Create the destination (Topic or Queue)
  Destination destination = testMeta.session.createQueue("TEST.FOO");

  // Create a MessageProducer from the Session to the Topic or Queue
  testMeta.producer = testMeta.session.createProducer(destination);
  testMeta.producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:20,代码来源:JMSObjectInputOperatorTest.java

示例13: testMessageExpire

import javax.jms.DeliveryMode; //导入依赖的package包/类
public void testMessageExpire() throws Exception {
   session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
   Topic topic = session.createTopic("TestTopic");
   consumer = session.createDurableSubscriber(topic, "sub1");
   producer = session.createProducer(topic);
   producer.setDeliveryMode(DeliveryMode.PERSISTENT);
   producer.setTimeToLive(1000);
   connection.start();

   // Make sure it works when the durable sub is active.
   producer.send(session.createTextMessage("Msg:1"));
   assertTextMessageEquals("Msg:1", consumer.receive(1000));

   consumer.close();

   producer.send(session.createTextMessage("Msg:2"));
   producer.send(session.createTextMessage("Msg:3"));

   consumer = session.createDurableSubscriber(topic, "sub1");

   // Try to get the message.
   assertTextMessageEquals("Msg:2", consumer.receive(1000));
   Thread.sleep(1000);
   assertNull(consumer.receive(1000));
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:DurableSubscriptionTestSupport.java

示例14: setUp

import javax.jms.DeliveryMode; //导入依赖的package包/类
/**
 * Sets a test to have a queue destination and non-persistent delivery mode.
 *
 * @see junit.framework.TestCase#setUp()
 */
@Override
protected void setUp() throws Exception {
   deliveryMode = DeliveryMode.NON_PERSISTENT;
   topic = false;
   super.setUp();
   consumerDestination2 = consumeSession.createTopic("FOO.BAR.HUMBUG2");
   LOG.info("Created  consumer destination: " + consumerDestination2 + " of type: " + consumerDestination2.getClass());
   if (durable) {
      LOG.info("Creating durable consumer");
      consumer2 = consumeSession.createDurableSubscriber((Topic) consumerDestination2, getName());
   } else {
      consumer2 = consumeSession.createConsumer(consumerDestination2);
   }

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:21,代码来源:JmsQueueTopicCompositeSendReceiveTest.java

示例15: start

import javax.jms.DeliveryMode; //导入依赖的package包/类
@Override
public void start() throws Exception {
    String uri = uriPrefix + hostName + ":" + port;
    LOG.info("ACTIVEMQ: Starting ActiveMQ on {}", uri);
    configure();

    broker = new BrokerService();
    broker.addConnector(uri);
    broker.start();

    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(uri + uriPostfix);
    Connection conn = factory.createConnection();
    conn.start();

    session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    dest = session.createQueue(queueName);
    consumer = session.createConsumer(dest);
    producer = session.createProducer(dest);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
 
开发者ID:sakserv,项目名称:hadoop-mini-clusters,代码行数:21,代码来源:ActivemqLocalBroker.java


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