當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。