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


Java Message類代碼示例

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


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

示例1: messageGetsPublished

import javax.jms.Message; //導入依賴的package包/類
@Test
public void messageGetsPublished() throws JMSException, InterruptedException {
  final TestConsumer testConsumer = new TestConsumer();
  cut.subscribe(testConsumer);

  EventMessage<?> eventMessage = GenericEventMessage
          .asEventMessage("SomePayload")
          .withMetaData(MetaData.with("key", "value"));

  Message jmsMessage = converter.createJmsMessage(eventMessage, topicSession);

  publisher.publish(jmsMessage);

  Thread.sleep(1000L);

  assertNotNull(testConsumer.latest);
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:18,代碼來源:JmsMessageSourceTest.java

示例2: validateFailOnUnsupportedMessageTypeOverJNDI

import javax.jms.Message; //導入依賴的package包/類
public void validateFailOnUnsupportedMessageTypeOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage();
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    try {
        consumer.consume(destinationName, new ConsumerCallback() {
            @Override
            public void accept(JMSResponse response) {
                // noop
            }
        });
    } finally {
        ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
    }
}
 
開發者ID:lsac,項目名稱:nifi-jms-jndi,代碼行數:24,代碼來源:JMSPublisherConsumerTest.java

示例3: addData

import javax.jms.Message; //導入依賴的package包/類
private void addData(Message message, String text) throws JMSException {
    MessageData data = new MessageData();
    data.setPayload(text);
    Map<String, String> headers = new HashMap<>();
    Enumeration<String> names = message.getPropertyNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        String value = message.getStringProperty(name);
        headers.put(name, value);
    }
    data.setHeaders(headers);
    messages.add(data);
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:14,代碼來源:JMSConsumer.java

示例4: startConsumer

import javax.jms.Message; //導入依賴的package包/類
private void startConsumer() {
    try {
        connection = connectionFactory.createConnection();
        connection.start();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination;
        if ("topic".equalsIgnoreCase(destinationType)) {
            destination = session.createTopic(destinationName);
        } else {
            destination = session.createQueue(destinationName);
        }

        consumer = session.createConsumer(destination);
        isStarted.compareAndSet(false, true);
        while (true) {
            Message message = consumer.receive();

            if (message instanceof TextMessage) {
                TextMessage textMessage = (TextMessage) message;
                String text = textMessage.getText();
                if (isRecording.get()) {
                    addData(message, text);
                }
                counter.incrementAndGet();
            }
        }

    } catch (Exception e) {
        //e.printStackTrace();
    } finally {
        terminate();
    }
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:34,代碼來源:JMSConsumer.java

示例5: testStringBodyIsApplied

import javax.jms.Message; //導入依賴的package包/類
@Test
public void testStringBodyIsApplied() throws JMSException {
    JMSProducer producer = context.createProducer();

    final String bodyValue = "String-Value";
    final AtomicBoolean bodyValidated = new AtomicBoolean();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            assertEquals(bodyValue, message.getBody(String.class));
            bodyValidated.set(true);
        }
    });

    producer.send(JMS_DESTINATION, bodyValue);
    assertTrue(bodyValidated.get());
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:21,代碼來源:JmsPoolJMSProducerTest.java

示例6: testMapBodyIsApplied

import javax.jms.Message; //導入依賴的package包/類
@Test
public void testMapBodyIsApplied() throws JMSException {
    JMSProducer producer = context.createProducer();

    final Map<String, Object> bodyValue = new HashMap<String, Object>();

    bodyValue.put("Value-1", "First");
    bodyValue.put("Value-2", "Second");

    final AtomicBoolean bodyValidated = new AtomicBoolean();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            assertEquals(bodyValue, message.getBody(Map.class));
            bodyValidated.set(true);
        }
    });

    producer.send(JMS_DESTINATION, bodyValue);
    assertTrue(bodyValidated.get());
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:25,代碼來源:JmsPoolJMSProducerTest.java

示例7: validateFailOnUnsupportedMessageType

import javax.jms.Message; //導入依賴的package包/類
/**
 * At the moment the only two supported message types are TextMessage and
 * BytesMessage which is sufficient for the type if JMS use cases NiFi is
 * used. The may change to the point where all message types are supported
 * at which point this test will no be longer required.
 */
@Test(expected = IllegalStateException.class)
public void validateFailOnUnsupportedMessageType() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage();
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    try {
        consumer.consume(destinationName, new ConsumerCallback() {
            @Override
            public void accept(JMSResponse response) {
                // noop
            }
        });
    } finally {
        ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
    }
}
 
開發者ID:SolaceLabs,項目名稱:solace-integration-guides,代碼行數:31,代碼來源:JMSPublisherConsumerTest.java

示例8: testRuntimeExceptionFromSendByteBody

import javax.jms.Message; //導入依賴的package包/類
@Test
public void testRuntimeExceptionFromSendByteBody() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), new byte[0]);
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:19,代碼來源:JmsPoolJMSProducerTest.java

示例9: testRuntimeExceptionFromSendSerializableBody

import javax.jms.Message; //導入依賴的package包/類
@Test
public void testRuntimeExceptionFromSendSerializableBody() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), UUID.randomUUID());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:19,代碼來源:JmsPoolJMSProducerTest.java

示例10: testRuntimeExceptionFromSendStringBody

import javax.jms.Message; //導入依賴的package包/類
@Test
public void testRuntimeExceptionFromSendStringBody() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), "test");
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:19,代碼來源:JmsPoolJMSProducerTest.java

示例11: onMessage

import javax.jms.Message; //導入依賴的package包/類
@Override
public void onMessage(final Message message) {
    BrpNu.set(DatumUtil.nuAlsZonedDateTime());
    try {
        LOGGER.debug("onMessage");
        final TextMessage textMessage = (TextMessage) message;
        final String text = textMessage.getText();
        final MaakSelectieResultaatTaak
                maakSelectieResultaatTaak =
                JSON_STRING_SERIALISEERDER.deserialiseerVanuitString(text, MaakSelectieResultaatTaak.class);
        final SoortSelectie soortSelectie = maakSelectieResultaatTaak.getSoortSelectie();
        if (soortSelectie == SoortSelectie.STANDAARD_SELECTIE) {
            maakSelectieResultaatTaakVerwerkerServiceImpl.verwerk(maakSelectieResultaatTaak);
        } else if (soortSelectie == SoortSelectie.SELECTIE_MET_PLAATSING_AFNEMERINDICATIE
                || soortSelectie == SoortSelectie.SELECTIE_MET_VERWIJDERING_AFNEMERINDICATIE) {
            afnemerindicatieMaakSelectieResultaatTaakVerwerkerServiceImpl.verwerk(maakSelectieResultaatTaak);
        }
    } catch (JMSException e) {
        LOGGER.error("error on message", e);
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:22,代碼來源:MaakSelectieResultaatTaakQueueMessageListener.java

示例12: onMessage

import javax.jms.Message; //導入依賴的package包/類
@Override
public void onMessage(final Message msg)
{
    try
    {
        taskPool.submit(new Callable<Boolean>()
        {
            @Override
            public Boolean call() throws Exception
            {
                return processMessage(msg);
            }
        });
    }
    catch (RejectedExecutionException e)
    {
        log.error("error while submitting message task, message: {}", msg, e);
    }
}
 
開發者ID:nuagenetworks,項目名稱:jmsclient,代碼行數:20,代碼來源:JMSMessageHandler.java

示例13: doSendTextMessage

import javax.jms.Message; //導入依賴的package包/類
private void doSendTextMessage( final Session session, final Destination destination,
                                final String textMessage,
                                final Map<String, ?> properties ) throws JMSException {

    try {
        final Message message = textMessage != null
                                                    ? session.createTextMessage(textMessage)
                                                    : session.createTextMessage();
        if (properties != null) {
            // Note: Setting any properties (including JMS fields) using
            // setObjectProperty might not be supported by all providers
            // Tested with: ActiveMQ
            for (final Entry<String, ?> property : properties.entrySet()) {
                message.setObjectProperty(property.getKey(), property.getValue());
            }
        }
        final MessageProducer producer = session.createProducer(destination);
        producer.send(message);
    } finally {
        releaseSession(false);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:23,代碼來源:JmsClient.java

示例14: isValidRequestResponse

import javax.jms.Message; //導入依賴的package包/類
/**
 * Since we use a request/response communication style with the client,
 * we must ensure that tha appropriate fields are set.
 */
private boolean isValidRequestResponse(Message incoming) {
    try {
        if (incoming.getJMSCorrelationID() == null) {
            getLogger().warn("JMSCorrelationID is not set! Will not process request");
            return false;
        }

        if (incoming.getJMSReplyTo() == null) {
            getLogger().warn("JMSReplyTo is not set! Will not process request");
            return false;
        }
    } catch (JMSException e) {
        getLogger().warn(
                "Failed to read JMSCorrelationID/JMSReplyTo. " +
                "Will not process request. Exception message = {}", e.getMessage());
        return false;
    }

    return true;
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:xsharing-services-router,代碼行數:25,代碼來源:AbstractSharingListener.java

示例15: sendWithReplyToTemp

import javax.jms.Message; //導入依賴的package包/類
private void sendWithReplyToTemp(ConnectionFactory cf, String serviceQueue) throws JMSException, InterruptedException {
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue tempQueue = session.createTemporaryQueue();
    TextMessage msg = session.createTextMessage("Request");
    msg.setJMSReplyTo(tempQueue);
    MessageProducer producer = session.createProducer(session.createQueue(serviceQueue));
    producer.send(msg);

    MessageConsumer consumer = session.createConsumer(tempQueue);
    Message replyMsg = consumer.receive();
    assertNotNull(replyMsg);

    LOG.debug("Reply message: {}", replyMsg);

    consumer.close();

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


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