當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。