當前位置: 首頁>>代碼示例>>Java>>正文


Java Session類代碼示例

本文整理匯總了Java中javax.jms.Session的典型用法代碼示例。如果您正苦於以下問題:Java Session類的具體用法?Java Session怎麽用?Java Session使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Session類屬於javax.jms包,在下文中一共展示了Session類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateMessages

import javax.jms.Session; //導入依賴的package包/類
/**
 * Generates JMS messages
 */
@PostConstruct
public void generateMessages() throws JMSException {
    for (int i = 0; i < messageCount; i++) {
        final int index = i;
        final String text = "Message number is " + i + ".";

        template.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage(text);
                message.setIntProperty(MESSAGE_COUNT, index);
                
                System.out.println("Sending message: " + text);
                
                return message;
            }
        });
    }
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:22,代碼來源:JmsMessageProducer.java

示例2: send

import javax.jms.Session; //導入依賴的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: createMessageProducer

import javax.jms.Session; //導入依賴的package包/類
public static MessageProducer createMessageProducer(
    Session session,
    Destination destination,
    MessageProducerOption producerOption) throws JMSException {

  MessageProducer producer = session.createProducer(destination);
  producer.setDeliveryDelay(producerOption.getDeliveryDelay());
  producer.setDeliveryMode(producerOption.getDeliveryMode());
  producer.setDisableMessageTimestamp(producerOption.isDisableMessageTimestamp());
  producer.setDisableMessageID(producerOption.isDisableMessageId());
  producer.setPriority(producerOption.getPriority());
  producer.setTimeToLive(producerOption.getTimeToLive());

  return producer;

}
 
開發者ID:bighector,項目名稱:-artemis-disruptor-miaosha,代碼行數:17,代碼來源:MessageProducerFactory.java

示例4: plaatsAfnemerberichten

import javax.jms.Session; //導入依賴的package包/類
@Override
public void plaatsAfnemerberichten(final List<AfnemerBericht> afnemerBerichten) {
    try {
        afnemersJmsTemplate.execute((final Session session, final MessageProducer producer) -> {
            for (final AfnemerBericht afnemerBericht : afnemerBerichten) {
                final SynchronisatieBerichtGegevens synchronisatieBerichtGegevens = afnemerBericht.getSynchronisatieBerichtGegevens();
                final Message message = session.createTextMessage(serializer.serialiseerNaarString(synchronisatieBerichtGegevens));
                message.setStringProperty(LeveringConstanten.JMS_MESSAGEGROUP_HEADER,
                        String.valueOf(synchronisatieBerichtGegevens.getArchiveringOpdracht().getOntvangendePartijId()));
                final ToegangLeveringsAutorisatie toegang = afnemerBericht.getToegangLeveringsAutorisatie();
                LOGGER.info("Zet bericht op de queue voor afnemer {} en kanaal {}",
                        toegang.getGeautoriseerde().getPartij().getNaam(),
                        toegang.getLeveringsautorisatie().getStelsel());
                producer.send(message);
            }
            return null;
        });
    } catch (final JmsException e) {
        LOGGER.error("fout in verzenden berichten naar afnemer queue", e);
        throw new BrpServiceRuntimeException(e);
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:23,代碼來源:PlaatsAfnemerBerichtServiceImpl.java

示例5: sendObjectMsgSingleSession

import javax.jms.Session; //導入依賴的package包/類
private void sendObjectMsgSingleSession(List<? extends Serializable> objectsToSend) throws JMSException {
    Session session = null;
    Connection conn = null;
    try {
        conn = qFactory.createConnection();
        session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        for (Serializable objectToSend : objectsToSend) {
            ObjectMessage msg = session.createObjectMessage();
            msg.setObject(objectToSend);
            producer.send(msg);
        }
    } finally {
        closeSession(session);
        closeConnection(conn);
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:18,代碼來源:TriggerQueueServiceBean.java

示例6: send

import javax.jms.Session; //導入依賴的package包/類
/**
 * Sends the given {@code events} to the configured JMS Topic. It takes the current Unit of Work
 * into account when available. Otherwise, it simply publishes directly.
 *
 * @param events the events to publish on the JMS Message Broker
 */
protected void send(List<? extends EventMessage<?>> events) {
  try (TopicConnection topicConnection = connectionFactory.createTopicConnection()) {
    int ackMode = isTransacted ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE;
    TopicSession topicSession = topicConnection.createTopicSession(isTransacted, ackMode);
    try (TopicPublisher publisher = topicSession.createPublisher(topic)) {
      for (EventMessage event : events) {
        Message jmsMessage = messageConverter.createJmsMessage(event, topicSession);
        doSendMessage(publisher, jmsMessage);
      }
    } finally {
      handleTransaction(topicSession);
    }
  } catch (JMSException ex) {
    throw new EventPublicationFailedException(
        "Unable to establish TopicConnection to JMS message broker.", ex);
  }
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:24,代碼來源:JmsPublisher.java

示例7: testGetTopicSubscriber

import javax.jms.Session; //導入依賴的package包/類
@Test
public void testGetTopicSubscriber() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    JmsPoolQueueReceiver receiver = (JmsPoolQueueReceiver) session.createReceiver(queue);

    assertNotNull(receiver.getQueueReceiver());
    assertTrue(receiver.getQueueReceiver() instanceof MockJMSQueueReceiver);

    receiver.close();

    try {
        receiver.getQueueReceiver();
        fail("Cannot read state on closed receiver");
    } catch (IllegalStateException ise) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:18,代碼來源:JmsPoolQueueReceiverTest.java

示例8: testReceiveTimed

import javax.jms.Session; //導入依賴的package包/類
@Test
public void testReceiveTimed() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    Session session = connection.createSession();
    Queue queue = session.createTemporaryQueue();
    MessageConsumer consumer = session.createConsumer(queue, "Color = Red");

    assertNull(consumer.receive(1));

    consumer.close();

    try {
        consumer.receive(1);
        fail("Should not be able to interact with closed consumer");
    } catch (IllegalStateException ise) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:17,代碼來源:JmsPoolMessageConusmerTest.java

示例9: doTestCreateMessageProducer

import javax.jms.Session; //導入依賴的package包/類
private void doTestCreateMessageProducer(boolean useAnonymousProducers) throws JMSException {
    cf.setUseAnonymousProducers(useAnonymousProducers);

    JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    Queue queue1 = session.createTemporaryQueue();
    Queue queue2 = session.createTemporaryQueue();

    JmsPoolMessageProducer producer1 = (JmsPoolMessageProducer) session.createProducer(queue1);
    JmsPoolMessageProducer producer2 = (JmsPoolMessageProducer) session.createProducer(queue2);

    if (useAnonymousProducers) {
        assertSame(producer1.getMessageProducer(), producer2.getMessageProducer());
    } else {
        assertNotSame(producer1.getMessageProducer(), producer2.getMessageProducer());
    }

    connection.close();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:21,代碼來源:JmsPoolWrappedProducersTest.java

示例10: doTestCreateTopicPublisher

import javax.jms.Session; //導入依賴的package包/類
private void doTestCreateTopicPublisher(boolean useAnonymousProducers) throws JMSException {
    cf.setUseAnonymousProducers(useAnonymousProducers);

    JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
    TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

    Topic topic1 = session.createTopic("Topic-1");
    Topic topic2 = session.createTopic("Topic-2");

    JmsPoolTopicPublisher publisher1 = (JmsPoolTopicPublisher) session.createPublisher(topic1);
    JmsPoolTopicPublisher publisher2 = (JmsPoolTopicPublisher) session.createPublisher(topic2);

    if (useAnonymousProducers) {
        assertSame(publisher1.getMessageProducer(), publisher2.getMessageProducer());
    } else {
        assertNotSame(publisher1.getMessageProducer(), publisher2.getMessageProducer());
    }

    connection.close();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:21,代碼來源:JmsPoolWrappedProducersTest.java

示例11: doTestCreateQueueSender

import javax.jms.Session; //導入依賴的package包/類
private void doTestCreateQueueSender(boolean useAnonymousProducers) throws JMSException {
    cf.setUseAnonymousProducers(useAnonymousProducers);

    JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    Queue queue1 = session.createTemporaryQueue();
    Queue queue2 = session.createTemporaryQueue();

    JmsPoolQueueSender sender1 = (JmsPoolQueueSender) session.createSender(queue1);
    JmsPoolQueueSender sender2 = (JmsPoolQueueSender) session.createSender(queue2);

    if (useAnonymousProducers) {
        assertSame(sender1.getMessageProducer(), sender2.getMessageProducer());
    } else {
        assertNotSame(sender1.getMessageProducer(), sender2.getMessageProducer());
    }

    connection.close();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:21,代碼來源:JmsPoolWrappedProducersTest.java

示例12: sendAndReceive

import javax.jms.Session; //導入依賴的package包/類
@Test
public void sendAndReceive() throws Exception {
  jmsTemplate.send("TEST.FOO", new MessageCreator() {
    @Override
    public Message createMessage(Session session) throws JMSException {
      return session.createTextMessage("Hello world");
    }
  });

  TextMessage received = (TextMessage) jmsTemplate.receive("TEST.FOO");
  assertEquals("Hello world", received.getText());

  jmsTemplate.convertAndSend("TEST.FOO", "Hello world");
  assertEquals("Hello world", jmsTemplate.receiveAndConvert("TEST.FOO"));

  List<MockSpan> mockSpans = mockTracer.finishedSpans();
  assertEquals(4, mockSpans.size());

  checkSpans(mockSpans);
  assertNull(mockTracer.activeSpan());
}
 
開發者ID:opentracing-contrib,項目名稱:java-jms,代碼行數:22,代碼來源:TracingJmsTemplateTest.java

示例13: validateFactoryCreationWithActiveMQLibraries

import javax.jms.Session; //導入依賴的package包/類
/**
 * This test simply validates that {@link ConnectionFactory} can be setup by
 * pointing to the location of the client libraries at runtime. It uses
 * ActiveMQ which is not present at the POM but instead pulled from Maven
 * repo using {@link TestUtils#setupActiveMqLibForTesting(boolean)}, which
 * implies that for this test to run the computer must be connected to the
 * Internet. If computer is not connected to the Internet, this test will
 * quietly fail logging a message.
 */
@Test
public void validateFactoryCreationWithActiveMQLibraries() throws Exception {
    try {
        String libPath = TestUtils.setupActiveMqLibForTesting(true);

        TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
        JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
        runner.addControllerService("cfProvider", cfProvider);
        runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI,
                "vm://localhost?broker.persistent=false");
        runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, libPath);
        runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
                "org.apache.activemq.ActiveMQConnectionFactory");
        runner.enableControllerService(cfProvider);
        runner.assertValid(cfProvider);

        Connection connection = cfProvider.getConnectionFactory().createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination queue = session.createQueue("myqueue");
        MessageProducer producer = session.createProducer(queue);
        MessageConsumer consumer = session.createConsumer(queue);

        TextMessage message = session.createTextMessage("Hello");
        producer.send(message);
        assertEquals("Hello", ((TextMessage) consumer.receive()).getText());
        connection.stop();
        connection.close();
    } catch (Exception e) {
        logger.error("'validateFactoryCreationWithActiveMQLibraries' failed due to ", e);
    }
}
 
開發者ID:SolaceLabs,項目名稱:solace-integration-guides,代碼行數:43,代碼來源:JMSConnectionFactoryProviderTest.java

示例14: getSession

import javax.jms.Session; //導入依賴的package包/類
protected Session getSession() {
    if (session == null) {
        synchronized (this) {
            if (closed)
                throw new IllegalStateRuntimeException("Context is closed");
            if (session == null) {
                try {
                    session = connection.createSession(sessionMode);
                } catch (JMSException e) {
                    throw Utils.convertToRuntimeException(e);
                }
            }
        }
    }
    return session;
}
 
開發者ID:ops4j,項目名稱:org.ops4j.pax.transx,代碼行數:17,代碼來源:JMSContextImpl.java

示例15: sendMessage

import javax.jms.Session; //導入依賴的package包/類
public void sendMessage() {
	jmsTemplate.send(notifyTopic, new MessageCreator() {
		@Override
		public Message createMessage(Session session) throws JMSException {

			MapMessage message = session.createMapMessage();
			
			int delay=10*1000;
			System.out.println("生產消消息");
			message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY,	 delay);
			message.setStringProperty("objectType", "user");

			return message;
		}
	});
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:17,代碼來源:AdvancedNotifyMessageProducer.java


注:本文中的javax.jms.Session類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。