How to use getReplyDestination method of com.consol.citrus.jms.endpoint.JmsSyncProducer class

Best Citrus code snippet using com.consol.citrus.jms.endpoint.JmsSyncProducer.getReplyDestination

Source:JmsSyncProducer.java Github

copy

Full Screen

...91 } else {92 throw new CitrusRuntimeException("Unable to send message - JMS destination not set");93 }94 messageProducer = session.createProducer(destination);95 replyToDestination = getReplyDestination(session, message);96 if (replyToDestination instanceof TemporaryQueue || replyToDestination instanceof TemporaryTopic) {97 messageConsumer = session.createConsumer(replyToDestination);98 }99 jmsRequest.setJMSReplyTo(replyToDestination);100 messageProducer.send(jmsRequest);101 if (messageConsumer == null) {102 messageConsumer = createMessageConsumer(replyToDestination, jmsRequest.getJMSMessageID());103 }104 log.info("Message was sent to JMS destination: '{}'", endpointConfiguration.getDestinationName(destination));105 log.debug("Receiving reply message on destination: '{}'", replyToDestination);106 javax.jms.Message jmsReplyMessage = (endpointConfiguration.getTimeout() >= 0) ? messageConsumer.receive(endpointConfiguration.getTimeout()) : messageConsumer.receive();107 if (jmsReplyMessage == null) {108 throw new ActionTimeoutException("Reply timed out after " +109 endpointConfiguration.getTimeout() + "ms. Did not receive reply message on reply destination");110 }111 Message responseMessage = endpointConfiguration.getMessageConverter().convertInbound(jmsReplyMessage, endpointConfiguration, context);112 log.info("Received reply message on JMS destination: '{}'", replyToDestination);113 context.onInboundMessage(responseMessage);114 correlationManager.store(correlationKey, responseMessage);115 } catch (JMSException e) {116 throw new CitrusRuntimeException(e);117 } finally {118 JmsUtils.closeMessageProducer(messageProducer);119 JmsUtils.closeMessageConsumer(messageConsumer);120 deleteTemporaryDestination(replyToDestination);121 }122 }123 @Override124 public Message receive(TestContext context) {125 return receive(correlationManager.getCorrelationKey(126 endpointConfiguration.getCorrelator().getCorrelationKeyName(getName()), context), context);127 }128 @Override129 public Message receive(String selector, TestContext context) {130 return receive(selector, context, endpointConfiguration.getTimeout());131 }132 @Override133 public Message receive(TestContext context, long timeout) {134 return receive(correlationManager.getCorrelationKey(135 endpointConfiguration.getCorrelator().getCorrelationKeyName(getName()), context), context, timeout);136 }137 @Override138 public Message receive(String selector, TestContext context, long timeout) {139 Message message = correlationManager.find(selector, timeout);140 if (message == null) {141 throw new ActionTimeoutException("Action timeout while receiving synchronous reply message on jms destination");142 }143 return message;144 }145 /**146 * Create new JMS connection.147 * @return connection148 * @throws JMSException149 */150 protected void createConnection() throws JMSException {151 if (connection == null) {152 if (!endpointConfiguration.isPubSubDomain() && endpointConfiguration.getConnectionFactory() instanceof QueueConnectionFactory) {153 connection = ((QueueConnectionFactory) endpointConfiguration.getConnectionFactory()).createQueueConnection();154 } else if (endpointConfiguration.isPubSubDomain() && endpointConfiguration.getConnectionFactory() instanceof TopicConnectionFactory) {155 connection = ((TopicConnectionFactory) endpointConfiguration.getConnectionFactory()).createTopicConnection();156 connection.setClientID(getName());157 } else {158 log.warn("Not able to create a connection with connection factory '" + endpointConfiguration.getConnectionFactory() + "'" +159 " when using setting 'publish-subscribe-domain' (=" + endpointConfiguration.isPubSubDomain() + ")");160 connection = endpointConfiguration.getConnectionFactory().createConnection();161 }162 connection.start();163 }164 }165 /**166 * Create new JMS session.167 * @param connection to use for session creation.168 * @return session.169 * @throws JMSException170 */171 protected void createSession(Connection connection) throws JMSException {172 if (session == null) {173 if (!endpointConfiguration.isPubSubDomain() && connection instanceof QueueConnection) {174 session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);175 } else if (endpointConfiguration.isPubSubDomain() && endpointConfiguration.getConnectionFactory() instanceof TopicConnectionFactory) {176 session = ((TopicConnection) connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);177 } else {178 log.warn("Not able to create a session with connection factory '" + endpointConfiguration.getConnectionFactory() + "'" +179 " when using setting 'publish-subscribe-domain' (=" + endpointConfiguration.isPubSubDomain() + ")");180 session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);181 }182 }183 }184 /**185 * Creates a message consumer on temporary/durable queue or topic. Durable queue/topic destinations186 * require a message selector to be set.187 *188 * @param replyToDestination the reply destination.189 * @param messageId the messageId used for optional message selector.190 * @return191 * @throws JMSException192 */193 private MessageConsumer createMessageConsumer(Destination replyToDestination, String messageId) throws JMSException {194 MessageConsumer messageConsumer;195 if (replyToDestination instanceof Queue) {196 messageConsumer = session.createConsumer(replyToDestination,197 "JMSCorrelationID = '" + messageId.replaceAll("'", "''") + "'");198 } else {199 messageConsumer = session.createDurableSubscriber((Topic)replyToDestination, getName(),200 "JMSCorrelationID = '" + messageId.replaceAll("'", "''") + "'", false);201 }202 return messageConsumer;203 }204 /**205 * Delete temporary destinations.206 * @param destination207 */208 private void deleteTemporaryDestination(Destination destination) {209 log.debug("Delete temporary destination: '{}'", destination);210 try {211 if (destination instanceof TemporaryQueue) {212 ((TemporaryQueue) destination).delete();213 } else if (destination instanceof TemporaryTopic) {214 ((TemporaryTopic) destination).delete();215 }216 } catch (JMSException e) {217 log.error("Error while deleting temporary destination '" + destination + "'", e);218 }219 }220 /**221 * Retrieve the reply destination either by injected instance, destination name or222 * by creating a new temporary destination.223 *224 * @param session current JMS session225 * @param message holding possible reply destination in header.226 * @return the reply destination.227 * @throws JMSException228 */229 private Destination getReplyDestination(Session session, Message message) throws JMSException {230 if (message.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL) != null) {231 if (message.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL) instanceof Destination) {232 return (Destination) message.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL);233 } else {234 return resolveDestinationName(message.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL).toString(), session);235 }236 } else if (endpointConfiguration.getReplyDestination() != null) {237 return endpointConfiguration.getReplyDestination();238 } else if (StringUtils.hasText(endpointConfiguration.getReplyDestinationName())) {239 return resolveDestinationName(endpointConfiguration.getReplyDestinationName(), session);240 }241 if (endpointConfiguration.isPubSubDomain() && session instanceof TopicSession) {242 return session.createTemporaryTopic();243 } else {244 return session.createTemporaryQueue();245 }246 }247 /**248 * Resolve destination from given name.249 * @param destinationName250 * @return251 * @throws JMSException252 */253 private Destination resolveDestination(String destinationName) throws JMSException {...

Full Screen

Full Screen

getReplyDestination

Using AI Code Generation

copy

Full Screen

1import org.springframework.context.annotation.Bean;2import org.springframework.context.annotation.Configuration;3import org.springframework.context.annotation.Import;4import com.consol.citrus.dsl.endpoint.CitrusEndpoints;5import com.consol.citrus.dsl.runner.TestRunner;6import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;7import com.consol.citrus.jms.endpoint.JmsEndpoint;8import com.consol.citrus.jms.endpoint.JmsSyncProducer;9import com.consol.citrus.message.MessageType;10import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;11import org.apache.activemq.ActiveMQConnectionFactory;12import org.apache.activemq.command.ActiveMQQueue;13import org.springframework.beans.factory.annotation.Autowired;14import org.testng.annotations.Test;15@Import(TestNGCitrusSpringSupport.class)16public class JmsSyncProducerTest extends TestRunnerBeforeSuiteSupport {17 private TestRunner runner;18 public JmsEndpoint jmsEndpoint() {19 return CitrusEndpoints.jms()20 .asynchronous()21 .connectionFactory(connectionFactory())22 .destination(destinationQueue())23 .build();24 }25 public JmsEndpoint jmsReplyEndpoint() {26 return CitrusEndpoints.jms()27 .asynchronous()28 .connectionFactory(connectionFactory())29 .destination(replyQueue())30 .build();31 }32 public ActiveMQConnectionFactory connectionFactory() {33 ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();34 return connectionFactory;35 }36 public ActiveMQQueue destinationQueue() {37 return new ActiveMQQueue("jms.queue.test");38 }39 public ActiveMQQueue replyQueue() {40 return new ActiveMQQueue("jms.queue.testReply");41 }42 public void testJmsSyncProducer() {43 runner.send(jmsEndpoint())44 .payload("Hello Citrus!");45 runner.receive(jmsEndpoint())46 .payload("Hello Citrus!")47 .header("operation", "sayHello");48 runner.send(jmsReplyEndpoint())49 .payload("Hello Citrus!")50 .header("operation", "sayHello");51 runner.receive(jmsReplyEndpoint())52 .payload("Hello Citrus!")53 .header("operation", "sayHello");54 }55}

Full Screen

Full Screen

getReplyDestination

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.runner.TestRunner2import com.consol.citrus.jms.endpoint.JmsSyncProducer3import com.consol.citrus.message.Message4import com.consol.citrus.dsl.builder.BuilderSupport5import com.consol.citrus.message.MessageType6import javax.jms.Destination7import javax.jms.Session8class CustomJmsSyncProducer extends JmsSyncProducer {9 protected Destination getReplyDestination(Message requestMessage, Session session) {10 return requestMessage.getHeaders().get("replyDestination")11 }12 protected BuilderSupport<Message> createMessageBuilder(Message requestMessage) {13 return super.createMessageBuilder(requestMessage).messageType(MessageType.BYTES)14 }15}16new CustomJmsSyncProducer()17 .connectionFactory(jmsConnectionFactory())18 .destinationName("myDestination")19new CustomJmsSyncProducer()20 .connectionFactory(jmsConnectionFactory())21 .destinationName("myDestination")22 .replyDestination("myReplyDestination")23new CustomJmsSyncProducer()24 .connectionFactory(jmsConnectionFactory())25 .destinationName("myDestination")26 .replyDestinationName("myReplyDestination")27new CustomJmsSyncProducer()28 .connectionFactory(jmsConnectionFactory())29 .destinationName("myDestination")30 .replyDestinationName("myReplyDestination-${correlationId}")31new CustomJmsSyncProducer()32 .connectionFactory(jmsConnectionFactory())33 .destinationName("myDestination")34 .replyDestination(jmsReplyDestination())35new CustomJmsSyncProducer()36 .connectionFactory(jmsConnectionFactory())37 .destinationName("myDestination")38 .replyDestinationName("myReplyDestination")

Full Screen

Full Screen

getReplyDestination

Using AI Code Generation

copy

Full Screen

1public void testJmsSyncProducer() {2 send(jmsSyncProducer()3 .destination("citrus:queue:inbound.queue")4 .messageType(String.class)5 .message("Hello Citrus!"));6 receive(jmsSyncProducer()7 .destination("citrus:queue:inbound.queue")8 .messageType(String.class)9 .getReplyDestination("citrus:queue:outbound.queue")10 .message("Hello Citrus!"));11}12public void testJmsSyncProducer() {13 send(jmsSyncProducer()14 .destination("citrus:topic:inbound.topic")15 .messageType(String.class)16 .message("Hello Citrus!"));17 receive(jmsSyncProducer()18 .destination("citrus:topic:inbound.topic")19 .messageType(String.class)20 .getReplyDestination("citrus:topic:outbound.topic")21 .message("Hello Citrus!"));22}23public void testJmsSyncProducer() {24 send(jmsSyncProducer()25 .destination("citrus:queue:inbound.queue")26 .messageType(String.class)27 .message("Hello Citrus!"));28 receive(jmsSyncProducer()29 .destination("citrus:queue:inbound.queue")30 .messageType(String.class)31 .getReplyDestination("citrus:topic:outbound.topic")32 .message("Hello Citrus!"));33}34public void testJmsSyncProducer() {35 send(jmsSyncProducer()36 .destination("citrus:topic:inbound.topic")

Full Screen

Full Screen

getReplyDestination

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.annotations.CitrusTest;2import com.consol.citrus.dsl.endpoint.CitrusEndpoints;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;4import com.consol.citrus.jms.endpoint.JmsSyncProducer;5import com.consol.citrus.message.MessageType;6import org.apache.activemq.command.ActiveMQQueue;7import org.apache.activemq.command.ActiveMQTemporaryQueue;8import org.springframework.beans.factory.annotation.Autowired;9import org.springframework.beans.factory.annotation.Qualifier;10import org.springframework.context.annotation.Bean;11import org.springframework.context.annotation.Configuration;12import org.springframework.jms.core.JmsTemplate;13import org.springframework.jms.core.MessageCreator;14import org.springframework.jms.support.destination.DestinationResolver;15import org.springframework.jms.support.destination.DynamicDestinationResolver;16import org.springframework.util.StringUtils;17import javax.jms.*;18public class JmsSyncProducerIT extends JUnit4CitrusTestDesigner {19 @Qualifier("jmsTemplate")20 private JmsTemplate jmsTemplate;21 @Qualifier("jmsDestinationResolver")22 private DestinationResolver destinationResolver;23 public JmsSyncProducer jmsSyncProducer() {24 .jms()25 .asynchronous()26 .connectionFactory(jmsTemplate.getConnectionFactory())27 .destinationResolver(destinationResolver)28 .destination("jms:queue:inbound.queue")29 .build();30 }31 public void jmsSyncProducerIT() {32 send(jmsSyncProducer())33 .payload("Hello World!")34 .header("operation", "greet");35 receive(jmsSyncProducer())36 .payload("Hello World!")37 .header("operation", "greet")38 .extractFromHeader("citrus_jms_replyTo", "destination");39 echo("Reply destination: ${destination}");40 send(jmsSyncProducer())41 .payload("Hello World!")42 .header("operation", "greet")43 .header("citrus_jms_replyTo", "${destination}");44 receive(jmsSyncProducer())45 .payload("Hello World!")46 .header("operation", "greet");47 send(jmsSyncProducer())48 .payload("Hello World!")49 .header("operation", "greet

Full Screen

Full Screen

getReplyDestination

Using AI Code Generation

copy

Full Screen

1public void testReplyDestination() {2 JmsMessage requestMessage = new JmsMessage("Hello World")3 .header("replyDestination", "replyQueue");4 JmsMessage replyMessage = new JmsMessage("Hello World");5 send(jmsEndpointBuilder()6 .destination("requestQueue")7 .build())8 .message(requestMessage);9 receive(jmsEndpointBuilder()10 .destination("replyQueue")11 .build())12 .message(replyMessage);13 send(jmsEndpointBuilder()14 .destination(jmsSyncProducer()15 .getReplyDestination(requestMessage))16 .build())17 .message(replyMessage);18}19public void testReplyDestination() {20 JmsMessage requestMessage = new JmsMessage("Hello World")21 .header("replyDestination", "replyQueue");22 JmsMessage replyMessage = new JmsMessage("Hello World");23 send(jmsEndpointBuilder()24 .destination("requestQueue")25 .build())26 .message(requestMessage);27 receive(jmsEndpointBuilder()28 .destination("replyQueue")29 .build())30 .message(replyMessage);31 send(jmsEndpointBuilder()32 .destination(jmsSyncProducer()33 .getReplyDestination(request

Full Screen

Full Screen

getReplyDestination

Using AI Code Generation

copy

Full Screen

1public void testGetReplyDestination() {2 context.createVariable("destinationName", "jms:queue:replyQueue");3 run(new TestCase()4 .actions(5 send("jms:queue:orders")6 .payload("<OrderRequest><text>Hello World!</text></OrderRequest>")7 .header("replyDestination", "${destinationName}"),8 receive("jms:queue:replyQueue")9 .payload("<OrderResponse><text>Hello Citrus!</text></OrderResponse>")10 );11}12public void testGetReplyDestination() {13 context.createVariable("destinationName", "jms:queue:replyQueue");14 run(new TestCase()15 .actions(16 send("jms:queue:orders")17 .payload("<OrderRequest><text>Hello World!</text></OrderRequest>")18 .header("replyDestination", "${destinationName}"),19 receive("jms:queue:replyQueue")20 .payload("<OrderResponse><text>Hello Citrus!</text></OrderResponse>")21 );22}23public void testGetReplyDestination() {24 context.createVariable("destinationName", "jms:queue:replyQueue");25 run(new TestCase()26 .actions(27 send("jms:queue:orders")28 .payload("<OrderRequest><text>Hello World!</text></OrderRequest>")29 .header("replyDestination", "${destinationName}"),30 receive("jms:queue:replyQueue")31 .payload("<OrderResponse><text>Hello Citrus!</text></OrderResponse>")32 );33}34public void testGetReplyDestination() {35 context.createVariable("destinationName", "jms:queue:

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful