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


Java JMSProducer.send方法代码示例

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


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

示例1: testStringBodyIsApplied

import javax.jms.JMSProducer; //导入方法依赖的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

示例2: testMapBodyIsApplied

import javax.jms.JMSProducer; //导入方法依赖的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

示例3: testSerializableBodyIsApplied

import javax.jms.JMSProducer; //导入方法依赖的package包/类
@Test
public void testSerializableBodyIsApplied() throws JMSException {
    JMSProducer producer = context.createProducer();

    final UUID bodyValue = UUID.randomUUID();
    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(UUID.class));
            bodyValidated.set(true);
        }
    });

    producer.send(JMS_DESTINATION, bodyValue);
    assertTrue(bodyValidated.get());
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:21,代码来源:JmsPoolJMSProducerTest.java

示例4: testRuntimeExceptionFromSendMessage

import javax.jms.JMSProducer; //导入方法依赖的package包/类
@Test
public void testRuntimeExceptionFromSendMessage() 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(), context.createMessage());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:19,代码来源:JmsPoolJMSProducerTest.java

示例5: testRuntimeExceptionFromSendByteBody

import javax.jms.JMSProducer; //导入方法依赖的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

示例6: testRuntimeExceptionFromSendMapBody

import javax.jms.JMSProducer; //导入方法依赖的package包/类
@Test
public void testRuntimeExceptionFromSendMapBody() 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(), Collections.<String, Object>emptyMap());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:19,代码来源:JmsPoolJMSProducerTest.java

示例7: testRuntimeExceptionFromSendSerializableBody

import javax.jms.JMSProducer; //导入方法依赖的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

示例8: testRuntimeExceptionFromSendStringBody

import javax.jms.JMSProducer; //导入方法依赖的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

示例9: testSendNullMessageThrowsMFRE

import javax.jms.JMSProducer; //导入方法依赖的package包/类
@Test
public void testSendNullMessageThrowsMFRE() throws JMSException {
    JMSProducer producer = context.createProducer();

    try {
        producer.send(JMS_DESTINATION, (Message) null);
        fail("Should throw a MessageFormatRuntimeException");
    } catch (MessageFormatRuntimeException mfre) {
    } catch (Exception e) {
        fail("Should throw a MessageFormatRuntimeException");
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:13,代码来源:JmsPoolJMSProducerTest.java

示例10: doTestSendAppliesDeliveryModeWithMessageBody

import javax.jms.JMSProducer; //导入方法依赖的package包/类
public void doTestSendAppliesDeliveryModeWithMessageBody(Class<?> bodyType) throws JMSException {
    JMSProducer producer = context.createProducer();

    final AtomicBoolean nonPersistentMessage = new AtomicBoolean();
    final AtomicBoolean persistentMessage = new AtomicBoolean();

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

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            if (!persistentMessage.get()) {
                assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
                persistentMessage.set(true);
            } else {
                assertEquals(DeliveryMode.NON_PERSISTENT, message.getJMSDeliveryMode());
                nonPersistentMessage.set(true);
            }
        }
    });

    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    producer.send(JMS_DESTINATION, "text");

    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    producer.send(JMS_DESTINATION, "text");

    assertTrue(persistentMessage.get());
    assertTrue(nonPersistentMessage.get());
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:31,代码来源:JmsPoolJMSProducerTest.java

示例11: doTestSendAppliesPriorityWithMessageBody

import javax.jms.JMSProducer; //导入方法依赖的package包/类
private void doTestSendAppliesPriorityWithMessageBody(Class<?> bodyType) throws JMSException {
    JMSProducer producer = context.createProducer();

    final AtomicBoolean lowPriority = new AtomicBoolean();
    final AtomicBoolean highPriority = new AtomicBoolean();

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

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            if (!lowPriority.get()) {
                assertEquals(0, message.getJMSPriority());
                lowPriority.set(true);
            } else {
                assertEquals(7, message.getJMSPriority());
                highPriority.set(true);
            }
        }
    });

    producer.setPriority(0);
    producer.send(JMS_DESTINATION, "text");

    producer.setPriority(7);
    producer.send(JMS_DESTINATION, "text");

    assertTrue(lowPriority.get());
    assertTrue(highPriority.get());
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:31,代码来源:JmsPoolJMSProducerTest.java

示例12: doTestSendAppliesTimeToLiveWithMessageBody

import javax.jms.JMSProducer; //导入方法依赖的package包/类
private void doTestSendAppliesTimeToLiveWithMessageBody(Class<?> bodyType) throws JMSException {
    JMSProducer producer = context.createProducer();

    final AtomicBoolean nonDefaultTTL = new AtomicBoolean();
    final AtomicBoolean defaultTTL = new AtomicBoolean();

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

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            if (!nonDefaultTTL.get()) {
                assertTrue(message.getJMSExpiration() > 0);
                nonDefaultTTL.set(true);
            } else {
                assertTrue(message.getJMSExpiration() == 0);
                defaultTTL.set(true);
            }
        }
    });

    producer.setTimeToLive(2000);
    producer.send(JMS_DESTINATION, "text");

    producer.setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
    producer.send(JMS_DESTINATION, "text");

    assertTrue(nonDefaultTTL.get());
    assertTrue(defaultTTL.get());
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:31,代码来源:JmsPoolJMSProducerTest.java

示例13: testBytesBodyIsApplied

import javax.jms.JMSProducer; //导入方法依赖的package包/类
@Test
public void testBytesBodyIsApplied() throws JMSException {
    JMSProducer producer = context.createProducer();

    final byte[] bodyValue = new byte[] { 0, 1, 2, 3, 4 };
    final AtomicBoolean bodyValidated = new AtomicBoolean();

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

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            byte[] payload = message.getBody(byte[].class);
            assertNotNull(payload);
            assertEquals(bodyValue.length, payload.length);

            for (int i = 0; i < payload.length; ++i) {
                assertEquals(bodyValue[i], payload[i]);
            }

            bodyValidated.set(true);
        }
    });

    producer.send(JMS_DESTINATION, bodyValue);
    assertTrue(bodyValidated.get());
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:28,代码来源:JmsPoolJMSProducerTest.java

示例14: testListener

import javax.jms.JMSProducer; //导入方法依赖的package包/类
@Test
@RunAsClient
public void testListener() throws JMSException, NamingException, InterruptedException {
	final Properties env = new Properties();
	env.put(INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
	env.put(PROVIDER_URL, "http-remoting://127.0.0.1:8080");

	Context namingContext = new InitialContext(env);

	ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(CONNECTION_FACTORY);
	logger.info("Got ConnectionFactory " + CONNECTION_FACTORY);

	Destination destination = (Destination) namingContext.lookup(REMOTE_QUEUE_LOOKUP);
	logger.info("Got JMS Endpoint " + REMOTE_QUEUE_LOOKUP);

	String question = "how many components in your family?";
	String response = "they are four";

	// Create the JMS context
	JMSContext context = connectionFactory.createContext(USER_NAME, USER_PASSWORD);
	Questionary questionary = new Questionary();
	questionary.setQuestion(question);
	questionary.setResponse(response);
	assertFalse("questionary is not approved", questionary.isApproved());
	JMSProducer producer = context.createProducer();
	producer.send(destination, questionary);

	JMSConsumer consumer = context.createConsumer(destination);
	MessageQueueListener messageQueueListener = new MessageQueueListener();
	consumer.setMessageListener(messageQueueListener);
	sleep(100);
	questionary = messageQueueListener.getQuestionary();
	assertEquals("the question is: ", question, questionary.getQuestion());
	assertEquals("the response is: ", response, questionary.getResponse());
	assertTrue("the message is approved: ", questionary.isApproved());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:37,代码来源:RemoteTestCase.java


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