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


Java JmsTemplate类代码示例

本文整理汇总了Java中org.springframework.jms.core.JmsTemplate的典型用法代码示例。如果您正苦于以下问题:Java JmsTemplate类的具体用法?Java JmsTemplate怎么用?Java JmsTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: validateBytesConvertedToBytesMessageOnSend

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
@Test
public void validateBytesConvertedToBytesMessageOnSend() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    publisher.publish(destinationName, "hellomq".getBytes());

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    byte[] bytes = new byte[7];
    ((BytesMessage) receivedMessage).readBytes(bytes);
    assertEquals("hellomq", new String(bytes));

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:17,代码来源:JMSPublisherConsumerTest.java

示例2: execute

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
public void execute(UserRepo userRepo) {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", Long.toString(userRepo.getId()));
    map.put("code", userRepo.getCode());
    map.put("name", userRepo.getName());

    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(connectionFactory);
    jmsTemplate.setPubSubDomain(true);

    try {
        jmsTemplate.convertAndSend(destinationName, jsonMapper.toJson(map));
    } catch (IOException ex) {
        logger.error(ex.getMessage());
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:17,代码来源:UserRepoPublisher.java

示例3: validateBytesConvertedToBytesMessageOnSendOverJNDI

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
@Test
public void validateBytesConvertedToBytesMessageOnSendOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    publisher.publish(destinationName, "hellomq".getBytes());

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    byte[] bytes = new byte[7];
    ((BytesMessage) receivedMessage).readBytes(bytes);
    assertEquals("hellomq", new String(bytes));

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:17,代码来源:JMSPublisherConsumerTest.java

示例4: validateJmsHeadersAndPropertiesAreTransferredFromFFAttributesOverJNDI

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
@Test
public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributesOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    Map<String, String> flowFileAttributes = new HashMap<>();
    flowFileAttributes.put("foo", "foo");
    flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic");
    publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes);

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    assertEquals("foo", receivedMessage.getStringProperty("foo"));
    assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic);
    assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:20,代码来源:JMSPublisherConsumerTest.java

示例5: validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
@Test
public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    Map<String, String> flowFileAttributes = new HashMap<>();
    flowFileAttributes.put("foo", "foo");
    flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic");
    publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes);

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    assertEquals("foo", receivedMessage.getStringProperty("foo"));
    assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic);
    assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:20,代码来源:JMSPublisherConsumerTest.java

示例6: 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

示例7: testReceiveLocalOnlyOptionsAppliedFromEnvOverridesURI

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
@Test
public void testReceiveLocalOnlyOptionsAppliedFromEnvOverridesURI() {
    load(EmptyConfiguration.class,
         "amqphub.amqp10jms.remote-url=amqp://127.0.0.1:5672" +
             "?jms.receiveLocalOnly=false&jms.receiveNoWaitLocalOnly=false",
         "amqphub.amqp10jms.receiveLocalOnly=true",
         "amqphub.amqp10jms.receiveNoWaitLocalOnly=true");

    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    JmsConnectionFactory connectionFactory =
        this.context.getBean(JmsConnectionFactory.class);

    assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);

    assertTrue(connectionFactory.isReceiveLocalOnly());
    assertTrue(connectionFactory.isReceiveNoWaitLocalOnly());
}
 
开发者ID:amqphub,项目名称:amqp-10-jms-spring-boot,代码行数:18,代码来源:AMQP10JMSAutoConfigurationTest.java

示例8: testDefaultsToLocalURI

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
@Test
public void testDefaultsToLocalURI() {
    load(EmptyConfiguration.class);

    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    ConnectionFactory connectionFactory =
        this.context.getBean(ConnectionFactory.class);

    assertTrue(connectionFactory instanceof JmsConnectionFactory);

    JmsConnectionFactory qpidJmsFactory = (JmsConnectionFactory) connectionFactory;

    assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
    assertEquals("amqp://localhost:5672", qpidJmsFactory.getRemoteURI());
    assertNull(qpidJmsFactory.getUsername());
    assertNull(qpidJmsFactory.getPassword());
}
 
开发者ID:amqphub,项目名称:amqp-10-jms-spring-boot,代码行数:18,代码来源:AMQP10JMSAutoConfigurationTest.java

示例9: main

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
public static void main(String[] args) throws Exception {


        ApplicationContext ctx = new ClassPathXmlApplicationContext(
          "com/springtraining/jms/JmsTemplateTest-context.xml");
        JmsTemplate template = (JmsTemplate) ctx.getBean("jmsTemplate");
        
       // for(int i=0; i<10; i++) {
            template.send("SpringSendTestQueue", new MessageCreator() {
                public Message createMessage(Session session)
                    throws JMSException {
                    TextMessage tm = session.createTextMessage();
                    tm.setText("This is a spring test message");
                    return tm;
                }
            });
            System.out.println("Message sent");
       // }
        System.exit(1);
    }
 
开发者ID:Illusionist80,项目名称:SpringTutorial,代码行数:21,代码来源:JmsTemplateTest.java

示例10: testReceiveLocalOnlyOptionsAppliedFromEnvOverridesURI

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
@Test
public void testReceiveLocalOnlyOptionsAppliedFromEnvOverridesURI() {
    load(EmptyConfiguration.class,
         "spring.qpidjms.remoteURL=amqp://127.0.0.1:5672" +
             "?jms.receiveLocalOnly=false&jms.receiveNoWaitLocalOnly=false",
         "spring.qpidjms.receiveLocalOnly=true",
         "spring.qpidjms.receiveNoWaitLocalOnly=true");

    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    JmsConnectionFactory connectionFactory =
        this.context.getBean(JmsConnectionFactory.class);

    assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);

    assertTrue(connectionFactory.isReceiveLocalOnly());
    assertTrue(connectionFactory.isReceiveNoWaitLocalOnly());
}
 
开发者ID:tabish121,项目名称:qpid-jms-spring-boot,代码行数:18,代码来源:QpidJMSAutoConfigurationTest.java

示例11: buildTargetResource

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
/**
 * This method essentially performs initialization of this Processor by
 * obtaining an instance of the {@link ConnectionFactory} from the
 * {@link JMSConnectionFactoryProvider} (ControllerService) and performing a
 * series of {@link ConnectionFactory} adaptations which eventually results
 * in an instance of the {@link CachingConnectionFactory} used to construct
 * {@link JmsTemplate} used by this Processor.
 */
private void buildTargetResource(ProcessContext context) {
    if (this.targetResource == null) {
        JMSConnectionFactoryProviderDefinition cfProvider = context.getProperty(CF_SERVICE).asControllerService(JMSConnectionFactoryProviderDefinition.class);
        ConnectionFactory connectionFactory = cfProvider.getConnectionFactory();

        UserCredentialsConnectionFactoryAdapter cfCredentialsAdapter = new UserCredentialsConnectionFactoryAdapter();
        cfCredentialsAdapter.setTargetConnectionFactory(connectionFactory);
        cfCredentialsAdapter.setUsername(context.getProperty(USER).getValue());
        cfCredentialsAdapter.setPassword(context.getProperty(PASSWORD).getValue());

        this.cachingConnectionFactory = new CachingConnectionFactory(cfCredentialsAdapter);
        this.cachingConnectionFactory.setSessionCacheSize(Integer.parseInt(context.getProperty(SESSION_CACHE_SIZE).getValue()));

        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setConnectionFactory(this.cachingConnectionFactory);
        jmsTemplate.setPubSubDomain(TOPIC.equals(context.getProperty(DESTINATION_TYPE).getValue()));

        // set of properties that may be good candidates for exposure via configuration
        jmsTemplate.setReceiveTimeout(1000);

        this.targetResource = this.finishBuildingTargetResource(jmsTemplate, context);
    }
}
 
开发者ID:SolaceLabs,项目名称:solace-integration-guides,代码行数:32,代码来源:AbstractJMSProcessor.java

示例12: 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

示例13: sendNotification

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
public void sendNotification(String destinationName, Object object) {
    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(connectionFactory);
    jmsTemplate.setPubSubDomain(true);

    try {
        jmsTemplate.convertAndSend(destinationName,
                jsonMapper.toJson(object));
    } catch (IOException ex) {
        logger.error(ex.getMessage());
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:13,代码来源:UserPublisher.java

示例14: testSpringLocalTx

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
@Test
public void testSpringLocalTx() throws Exception {
    ConnectionFactory cf = createCF(BROKER_URL);
    JmsTemplate jms = new JmsTemplate(cf);
    jms.setDefaultDestinationName(QUEUE);
    jms.setReceiveTimeout(1000);
    PlatformTransactionManager tm = new JmsTransactionManager(cf);
    TransactionTemplate localTx = new TransactionTemplate(tm);

    localTx.execute(ts -> {
        jms.convertAndSend("Hello");
        return null;
    });
    Object msg = localTx.execute(ts -> jms.receiveAndConvert());
    assertEquals("Hello", msg);

    localTx.execute(ts -> {
        jms.convertAndSend("Hello");
        ts.setRollbackOnly();
        return null;
    });
    msg = localTx.execute(ts -> jms.receiveAndConvert());
    assertNull(msg);
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:25,代码来源:ActiveMQTest.java

示例15: testLookupIdFound

import org.springframework.jms.core.JmsTemplate; //导入依赖的package包/类
@Test
public void testLookupIdFound() throws JMSException {
	System.setProperty("manifestIdLookupThreshold", ""+LOOKUP_THRESHOLD);
	SensorPublisher publisher = new SensorPublisher();
	JmsTemplate[] array = {mock(JmsTemplate.class)};
	publisher.setProducers(array);
	PerfEvent event = new PerfEvent();
	ThresholdsDao dao = mock(ThresholdsDao.class);
	when(dao.getManifestId(100)).thenReturn(1L);
	Threshold t = new Threshold();
	t.setThresholdJson("{}");
	t.setHeartbeat(true);
	when(dao.getThreshold(1, "null")).thenReturn(t);
	publisher.setThresholdDao(dao);
	event.setCiId(100);
	publisher.enrichAndPublish(event);
	publisher.enrichAndPublish(event);
	verify(dao).getManifestId(100);
	verify(dao, times(1)).getThreshold(1,"null");
	assertEquals( publisher.getPublishedCounter(), 2);
	verifyNoMoreInteractions(dao);
}
 
开发者ID:oneops,项目名称:oneops,代码行数:23,代码来源:SensorPublisherTest.java


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