List of usage examples for org.springframework.jms.core JmsTemplate setMessageConverter
public void setMessageConverter(@Nullable MessageConverter messageConverter)
From source file:ru.anr.base.facade.jmsclient.JmsConfig.java
/** * Constructing a JMS template bean//from w w w . j a va 2 s .co m * * @param connectionFactory * {@link ConnectionFactory} * @return Bean instance */ @Bean(name = "jmsTemplate") @DependsOn("connectionFactory") public JmsTemplate template(@Qualifier("connectionFactory") ConnectionFactory connectionFactory) { JmsTemplate template = new JmsTemplate(connectionFactory); template.setMessageConverter(new MessagingMessageConverter()); if (receiveTimeout != null) { template.setReceiveTimeout(receiveTimeout); } return template; }
From source file:com.consol.citrus.demo.voting.jms.JmsConfig.java
@Bean public JmsTemplate jmsTemplate() { JmsTemplate jmsTemplate = new JmsTemplate(); jmsTemplate.setConnectionFactory(activeMqConnectionFactory()); jmsTemplate.setMessageConverter(jacksonJmsMessageConverter()); return jmsTemplate; }
From source file:com.jim.im.config.GenericMQConfig.java
@Bean public JmsTemplate jmsTemplate(ConnectionFactory connectionFactory, JmsProperties properties, MessageConverter messageConverter, DestinationResolver destinationResolver) { JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory); jmsTemplate.setMessageConverter(messageConverter); jmsTemplate.setPubSubDomain(properties.isPubSubDomain()); jmsTemplate.setDeliveryMode(Session.AUTO_ACKNOWLEDGE); if (destinationResolver != null) { jmsTemplate.setDestinationResolver(destinationResolver); }/*from w w w . ja v a2 s.c o m*/ jmsTemplate.setDefaultDestinationName(IMConstant.MQ_FORWARD_TOPIC_NAME); return jmsTemplate; }
From source file:com.kinglcc.spring.jms.config.JmsAnnotationAtuoConfiguration.java
@Bean @ConditionalOnMissingBean//from ww w.j a v a 2s. c o m public JmsTemplate jmsTemplate(ConnectionFactory connectionFactory) { JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory); jmsTemplate.setPubSubDomain(this.properties.isPubSubDomain()); if (this.destinationResolver != null) { jmsTemplate.setDestinationResolver(this.destinationResolver); } jmsTemplate.setMessageConverter(messageConverter); return jmsTemplate; }
From source file:com.atlantbh.jmeter.plugins.jmstools.JmsUtil.java
@Override public SampleResult runTest(JavaSamplerContext ctx) { SampleResult result = new SampleResult(); result.setContentType("plain/text"); result.setDataType(SampleResult.TEXT); result.setDataEncoding(SampleResult.DEFAULT_HTTP_ENCODING); String connectionUrl = ctx.getParameter("connection.url"); String bindingUrl = ctx.getParameter("binding.url"); String message = ctx.getParameter("message"); if (connectionUrl == null || "".equals(connectionUrl)) { result.setSuccessful(false);/*w w w. j a va2 s . c om*/ result.setResponseMessage("Connection URL cannot be empty."); result.setResponseCode("0xDEAD"); } else { if (bindingUrl == null || "".equals(bindingUrl)) { result.setSuccessful(false); result.setResponseMessage("Binding URL cannot be empty."); result.setResponseCode("0xDEAD"); } else { try { ConnectionFactory connectionFactory = new AMQConnectionFactory(connectionUrl); AMQBindingURL burl = new AMQBindingURL(bindingUrl); Destination destinationProducer = new AMQAnyDestination(burl); JmsTemplate sender = new JmsTemplate(); sender.setConnectionFactory(connectionFactory); sender.setDefaultDestination(destinationProducer); BinaryMessageConverter bmc = new BinaryMessageConverter(); sender.setMessageConverter(bmc); BinaryMessagepostProcessor postProcessor = new BinaryMessagepostProcessor(); sender.setDeliveryMode(2); int rt = 30000; try { rt = Integer.valueOf(ctx.getParameter("receive.timeout")); } catch (Exception e) { } sender.setReceiveTimeout(rt); String direction = ctx.getParameter("direction"); if (direction == null || "".equals(direction)) { direction = "send"; } if (direction.toLowerCase().equals("send")) { Map<String, String> mp = getMessageProperties(ctx.getParameter("header.properties")); postProcessor.setMessageProperties(mp); sender.convertAndSend((Object) message, postProcessor); result.setSuccessful(true); result.setResponseMessage("Message sent."); } else { if (direction.toLowerCase().equals("receive")) { System.out.println("Receive"); String messageSelector = ctx.getParameter("message.selector"); System.out.println("Selector: " + messageSelector); Object obj = null; if (messageSelector != null && !"".equals(messageSelector)) { obj = sender.receiveSelectedAndConvert(messageSelector); } else { obj = sender.receiveAndConvert(); } if (obj != null) { result.setSuccessful(true); result.setResponseData(obj.toString().getBytes()); String paramName = ctx.getParameter("header.property.reference"); if (paramName != null && !"".equals(paramName)) JMeterUtils.setProperty(paramName, concatProperties(bmc.getMessageProperties())); } else { result.setSuccessful(false); result.setResponseData("Conection timeout".getBytes()); } } else { result.setSuccessful(false); result.setResponseMessage("Unknown direction."); } } } catch (Exception e) { e.printStackTrace(); result.setSuccessful(!true); result.setResponseMessage("Exception"); result.setResponseData(e.getMessage().getBytes()); } } } return result; }
From source file:com.ruyicai.msgcenter.jms.WithoutTMJmsConfiguration.java
/** * Creates a {@link JmsOperations} object used for one way messaging *//*from www . j a va2 s . com*/ public JmsOperations createInOnlyTemplate(JmsEndpoint endpoint, boolean pubSubDomain, String destination) { if (jmsOperations != null) { return jmsOperations; } ConnectionFactory factory = getTemplateConnectionFactory(); JmsTemplate template = new CamelJmsTemplate(this, factory); template.setPubSubDomain(pubSubDomain); if (destinationResolver != null) { template.setDestinationResolver(destinationResolver); if (endpoint instanceof DestinationEndpoint) { LOG.debug( "You are overloading the destinationResolver property on a DestinationEndpoint; are you sure you want to do that?"); } } else if (endpoint instanceof DestinationEndpoint) { DestinationEndpoint destinationEndpoint = (DestinationEndpoint) endpoint; template.setDestinationResolver(createDestinationResolver(destinationEndpoint)); } template.setDefaultDestinationName(destination); template.setExplicitQosEnabled(isExplicitQosEnabled()); template.setDeliveryPersistent(deliveryPersistent); if (messageConverter != null) { template.setMessageConverter(messageConverter); } template.setMessageIdEnabled(messageIdEnabled); template.setMessageTimestampEnabled(messageTimestampEnabled); if (priority >= 0) { template.setPriority(priority); } template.setPubSubNoLocal(pubSubNoLocal); if (receiveTimeout >= 0) { template.setReceiveTimeout(receiveTimeout); } // only set TTL if we have a positive value and it has not been disabled if (timeToLive >= 0 && !isDisableTimeToLive()) { template.setTimeToLive(timeToLive); } template.setSessionTransacted(transacted); if (transacted) { template.setSessionAcknowledgeMode(Session.SESSION_TRANSACTED); } else { // This is here for completeness, but the template should not get // used for receiving messages. if (acknowledgementMode >= 0) { template.setSessionAcknowledgeMode(acknowledgementMode); } else if (acknowledgementModeName != null) { template.setSessionAcknowledgeModeName(acknowledgementModeName); } } return template; }
From source file:org.apache.camel.component.jms.JmsConfiguration.java
/** * Creates a {@link JmsOperations} object used for one way messaging *///from w ww.j a v a 2 s . co m public JmsOperations createInOnlyTemplate(JmsEndpoint endpoint, boolean pubSubDomain, String destination) { if (jmsOperations != null) { return jmsOperations; } ConnectionFactory factory = getTemplateConnectionFactory(); JmsTemplate template = new CamelJmsTemplate(this, factory); template.setPubSubDomain(pubSubDomain); if (destinationResolver != null) { template.setDestinationResolver(destinationResolver); if (endpoint instanceof DestinationEndpoint) { LOG.debug( "You are overloading the destinationResolver property on a DestinationEndpoint; are you sure you want to do that?"); } } else if (endpoint instanceof DestinationEndpoint) { DestinationEndpoint destinationEndpoint = (DestinationEndpoint) endpoint; template.setDestinationResolver(createDestinationResolver(destinationEndpoint)); } template.setDefaultDestinationName(destination); template.setExplicitQosEnabled(isExplicitQosEnabled()); template.setDeliveryPersistent(deliveryPersistent); if (messageConverter != null) { template.setMessageConverter(messageConverter); } template.setMessageIdEnabled(messageIdEnabled); template.setMessageTimestampEnabled(messageTimestampEnabled); if (priority >= 0) { template.setPriority(priority); } template.setPubSubNoLocal(pubSubNoLocal); if (receiveTimeout >= 0) { template.setReceiveTimeout(receiveTimeout); } if (timeToLive >= 0) { template.setTimeToLive(timeToLive); } template.setSessionTransacted(transacted); if (transacted) { template.setSessionAcknowledgeMode(Session.SESSION_TRANSACTED); } else { // This is here for completeness, but the template should not get // used for receiving messages. if (acknowledgementMode >= 0) { template.setSessionAcknowledgeMode(acknowledgementMode); } else if (acknowledgementModeName != null) { template.setSessionAcknowledgeModeName(acknowledgementModeName); } } return template; }
From source file:org.springframework.util.jms.JmsIntegrationTestUtils.java
public static void startAndConnectToJmsBroker(Class<?> clzzForPayload, Marshaller m, JmsBrokerExecutionCallback callback) throws Throwable { Assert.assertNotNull("the " + JmsBrokerExecutionCallback.class.getName() + "can not be null", callback); String destinationUrl = "tcp://localhost:61617"; BrokerService broker = new BrokerService(); TransportConnector connector = broker.addConnector(destinationUrl); broker.start();// w w w . ja va2s . c om while (!broker.isStarted()) { Thread.sleep(500); } ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(destinationUrl); MarshallingMessageConverter converter = new MarshallingMessageConverter(clzzForPayload, m); JmsTemplate jmsTemplate = new JmsTemplate(activeMQConnectionFactory); converter.setPayloadClass(clzzForPayload); jmsTemplate.setMessageConverter(converter); jmsTemplate.afterPropertiesSet(); try { callback.doWithActiveMq(broker, jmsTemplate); } catch (AssertionError ae) { throw ae; } catch (Throwable th) { if (log.isErrorEnabled()) { log.error("execution of jms session failed.", th); } } finally { connector.stop(); broker.stop(); } }