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


Java JmsTemplate.send方法代碼示例

本文整理匯總了Java中org.springframework.jms.core.JmsTemplate.send方法的典型用法代碼示例。如果您正苦於以下問題:Java JmsTemplate.send方法的具體用法?Java JmsTemplate.send怎麽用?Java JmsTemplate.send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.jms.core.JmsTemplate的用法示例。


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

示例1: validateFailOnUnsupportedMessageTypeOverJNDI

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的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

示例2: validateFailOnUnsupportedMessageType

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的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

示例3: sendMessageDelay

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
 * 延遲發送對象消息
 * @param jmsTemplate
 * @param destination
 * @param objectMessage
 * @param delay
 */
public static void sendMessageDelay(JmsTemplate jmsTemplate, Destination destination, final Serializable objectMessage, final long delay) {
    jmsTemplate.send(destination, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            ObjectMessage om = session.createObjectMessage(objectMessage);
            om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
            om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1 * 1000);
            om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
            return om;
        }
    });
}
 
開發者ID:ChangyiHuang,項目名稱:shuzheng,代碼行數:20,代碼來源:JmsUtil.java

示例4: send

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
 * 發送數據
 * @param jmsTemplate
 * @param queue
 */
public void send(JmsTemplate jmsTemplate,ActiveMQDestination queue){
    for(int i=0;i<10;i++){
        final int k=i;
        //發送消息
        jmsTemplate.send(queue, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage("hello!this is number:"+k);
            }
        });
    }

}
 
開發者ID:tomoncle,項目名稱:JavaStudy,代碼行數:19,代碼來源:App.java

示例5: sendMessage

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
 * 發送文本消息
 * @param jmsTemplate
 * @param destination
 * @param textMessage
 */
public static void sendMessage(JmsTemplate jmsTemplate, Destination destination, final String textMessage) {
    jmsTemplate.send(destination, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(textMessage);
        }
    });
}
 
開發者ID:ChangyiHuang,項目名稱:shuzheng,代碼行數:15,代碼來源:JmsUtil.java

示例6: validateConsumeWithCustomHeadersAndProperties

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
@Test
public void validateConsumeWithCustomHeadersAndProperties() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage("hello from the other side");
            message.setStringProperty("foo", "foo");
            message.setBooleanProperty("bar", false);
            message.setJMSReplyTo(session.createQueue("fooQueue"));
            return message;
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    final AtomicBoolean callbackInvoked = new AtomicBoolean();
    consumer.consume(destinationName, new ConsumerCallback() {
        @Override
        public void accept(JMSResponse response) {
            callbackInvoked.set(true);
            assertEquals("hello from the other side", new String(response.getMessageBody()));
            assertEquals("fooQueue", response.getMessageHeaders().get(JmsHeaders.REPLY_TO));
            assertEquals("foo", response.getMessageProperties().get("foo"));
            assertEquals("false", response.getMessageProperties().get("bar"));
        }
    });
    assertTrue(callbackInvoked.get());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
開發者ID:lsac,項目名稱:nifi-jms-jndi,代碼行數:33,代碼來源:JMSPublisherConsumerTest.java

示例7: sendMessageDelay

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
 * 延遲發送對象消息
 * @param jmsTemplate
 * @param destination
 * @param objectMessage
 * @param delay
 */
public static void sendMessageDelay(JmsTemplate jmsTemplate, Destination destination, final Serializable objectMessage, final long delay) {
    jmsTemplate.send(destination, new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            ObjectMessage om = session.createObjectMessage(objectMessage);
            om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
            om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1 * 1000);
            om.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
            return om;
        }
    });
}
 
開發者ID:lgpzjp,項目名稱:rure,代碼行數:19,代碼來源:JmsUtil.java

示例8: sendMessage

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
 * 發送文本消息
 * @param jmsTemplate
 * @param destination
 * @param textMessage
 */
public static void sendMessage(JmsTemplate jmsTemplate, Destination destination, final String textMessage) {
    jmsTemplate.send(destination, new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(textMessage);
        }
    });
}
 
開發者ID:youngMen1,項目名稱:-Spring-SpringMVC-Mybatis-,代碼行數:14,代碼來源:JmsUtil.java

示例9: validateConsumeWithCustomHeadersAndPropertiesOverJNDI

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
@Test
public void validateConsumeWithCustomHeadersAndPropertiesOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage("hello from the other side");
            message.setStringProperty("foo", "foo");
            message.setBooleanProperty("bar", false);
            message.setJMSReplyTo(session.createQueue("fooQueue"));
            return message;
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    final AtomicBoolean callbackInvoked = new AtomicBoolean();
    consumer.consume(destinationName, new ConsumerCallback() {
        @Override
        public void accept(JMSResponse response) {
            callbackInvoked.set(true);
            assertEquals("hello from the other side", new String(response.getMessageBody()));
            assertEquals("fooQueue", response.getMessageHeaders().get(JmsHeaders.REPLY_TO));
            assertEquals("foo", response.getMessageProperties().get("foo"));
            assertEquals("false", response.getMessageProperties().get("bar"));
        }
    });
    assertTrue(callbackInvoked.get());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
開發者ID:SolaceLabs,項目名稱:solace-integration-guides,代碼行數:33,代碼來源:JMSPublisherConsumerTest.java

示例10: sendMessage

import org.springframework.jms.core.JmsTemplate; //導入方法依賴的package包/類
/**
 * 發送對象消息
 * @param jmsTemplate
 * @param destination
 * @param objectMessage
 */
public static void sendMessage(JmsTemplate jmsTemplate, Destination destination, final Serializable objectMessage) {
    jmsTemplate.send(destination, new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage(objectMessage);
        }
    });
}
 
開發者ID:lgpzjp,項目名稱:rure,代碼行數:14,代碼來源:JmsUtil.java


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