当前位置: 首页>>代码示例>>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;未经允许,请勿转载。