Java Code Examples for org.springframework.jms.core.JmsTemplate#convertAndSend()
The following examples show how to use
org.springframework.jms.core.JmsTemplate#convertAndSend() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringBootJmsV2Application.java From pro-spring-boot with Apache License 2.0 | 6 votes |
@Bean CommandLineRunner start(JmsTemplate template){ return args -> { log.info("Sending> ..."); template.convertAndSend(queue, "SpringBoot Rocks!"); }; }
Example 2
Source File: UserRepoPublisher.java From lemon with Apache License 2.0 | 6 votes |
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()); } }
Example 3
Source File: Application.java From Spring with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { final ConfigurableApplicationContext context = SpringApplication.run(Application.class, args); final JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class); //Send an user log.info("#### Sending an user message."); jmsTemplate.convertAndSend("userQueue", new User("[email protected]", 5d, true)); log.info("#### Waiting for user and confirmation ..."); System.in.read(); context.close(); }
Example 4
Source File: SpringJmsTest.java From java-specialagent with Apache License 2.0 | 5 votes |
@Test public void test(final MockTracer tracer) { try (final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(RabbitConfiguration.class)) { final JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class); jmsTemplate.convertAndSend("mailbox", "message"); await().atMost(15, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(2)); assertEquals(1, counter.get()); final List<MockSpan> spans = tracer.finishedSpans(); assertEquals(2, spans.size()); } }
Example 5
Source File: SpringBootJmsV2Application.java From pro-spring-boot with Apache License 2.0 | 5 votes |
@Bean CommandLineRunner start(JmsTemplate template){ return args -> { log.info("Sending> ..."); template.convertAndSend(queue, "SpringBoot Rocks!"); }; }
Example 6
Source File: Main.java From java-course-ee with MIT License | 5 votes |
public static void main(String[] args) throws InterruptedException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml"); Thread.sleep(5000); JmsTemplate jmsTemplate = context.getBean("jmsTemplate", JmsTemplate.class); for (int i = 0; i < 10; i++) { jmsTemplate.convertAndSend("test-queue", "test message: " + i); } }
Example 7
Source File: UserPublisher.java From lemon with Apache License 2.0 | 5 votes |
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()); } }
Example 8
Source File: UserPublisher.java From lemon with Apache License 2.0 | 5 votes |
public void sendSynchronization(String destinationName, Object object) { JmsTemplate jmsTemplate = new JmsTemplate(); jmsTemplate.setConnectionFactory(connectionFactory); jmsTemplate.setPubSubDomain(false); try { jmsTemplate.convertAndSend(destinationName, jsonMapper.toJson(object)); } catch (IOException ex) { logger.error(ex.getMessage()); } }
Example 9
Source File: ArquillianTest.java From kubernetes-integration-test with Apache License 2.0 | 4 votes |
@Test public void testSucc() throws Exception { log.info("Test resources are in namespace:"+session.getNamespace()); //OpenShift client - here for example log.info("OpenShift - getMasterUrl: {}", oc.getMasterUrl()); log.info("OpenShift - getApiVersion: {}", oc.getApiVersion()); log.info("OpenShift - currentUser: {}", oc.currentUser().getMetadata().getName()); log.info("OpenShift - getNamespace: {}", oc.getNamespace()); log.info("OpenShift - getConfiguration: {}", oc.getConfiguration()); log.info("OpenShift - getClass: {}", oc.getClass()); //Kubernetes client - here for example log.info("Kubernetes - getMasterUrl: {}", client.getMasterUrl()); log.info("Kubernetes - getApiVersion: {}", client.getApiVersion()); log.info("Kubernetes - getConfiguration: {}", client.getConfiguration()); log.info("Kubernetes - getClass: {}", client.getClass()); //Service in the current namespace oc.services().list().getItems().stream() .map(s->s.getMetadata().getNamespace()+" - "+s.getMetadata().getName()) .forEach(s->log.info("Service: {}",s)); /************* * Start test *************/ //The port-foward url has http schema, but it's actually the amq 61616 port String brokerUrl = "tcp://"+ amqsvcUrl.getHost()+":"+ amqsvcUrl.getPort(); log.info("brokerUrl: {}",brokerUrl); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("test","secret",brokerUrl); JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory); //Send test message and receive outcome jmsTemplate.convertAndSend("user.in", "{\"email\":\"[email protected]\"}"); TextMessage message = (TextMessage) jmsTemplate.receive("user.out"); String response = message.getText(); log.info("Response: {}",response); //Asserts assertEquals("[email protected]", JsonPath.read(response, "$.email")); assertEquals("5551234567", JsonPath.read(response, "$.phone")); assertEquals("Test State", JsonPath.read(response, "$.address.state")); assertEquals("Test City", JsonPath.read(response, "$.address.city")); assertEquals("1 Test St", JsonPath.read(response, "$.address.address")); assertEquals("T001", JsonPath.read(response, "$.address.zip")); }
Example 10
Source File: ArquillianTest.java From kubernetes-integration-test with Apache License 2.0 | 4 votes |
@Test public void shutDownMariadb() throws Exception{ //Delete mariadb pod log.info("mariadb: {}", oc.pods().withName("mariadb").get()); //not null log.info("Delete mariadb pod."); assertTrue( oc.pods().withName(mariadb.getMetadata().getName()).delete() ); Awaitility.await().atMost(30,TimeUnit.SECONDS).until(()->oc.pods().withName("mariadb").get()==null); //The port-foward url has http schema, but it's actually the amq 61616 port String brokerUrl = "tcp://"+ amqsvcUrl.getHost()+":"+ amqsvcUrl.getPort(); log.info("brokerUrl: {}",brokerUrl); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("test","secret",brokerUrl); JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory); //Send test message and receive outcome jmsTemplate.convertAndSend("user.in", "{\"email\":\"[email protected]\"}"); //Wait a sec to make sure message fails Thread.sleep(3000); //Create mariadb Pod and load sql log.info("Create mariadb pod."); ObjectMeta emptyObjectMeta = new ObjectMeta(); emptyObjectMeta.setName(mariadb.getMetadata().getName()); emptyObjectMeta.setLabels(mariadb.getMetadata().getLabels()); mariadb.setMetadata(emptyObjectMeta); mariadb.setStatus(null); Pod newPod = oc.pods().create(mariadb); log.info("mariadb: {}", oc.pods().withName("mariadb").get()); Awaitility.await().atMost(30,TimeUnit.SECONDS).until(()->oc.pods().withName("mariadb").isReady()); //Recreate table, load data loadSql(); //Receive response message TextMessage message = (TextMessage) jmsTemplate.receive("user.out"); String response = message.getText(); log.info("Response: {}",response); //Asserts assertEquals("[email protected]", JsonPath.read(response, "$.email")); assertEquals("5551234567", JsonPath.read(response, "$.phone")); assertEquals("Test State", JsonPath.read(response, "$.address.state")); assertEquals("Test City", JsonPath.read(response, "$.address.city")); assertEquals("1 Test St", JsonPath.read(response, "$.address.address")); assertEquals("T001", JsonPath.read(response, "$.address.zip")); }
Example 11
Source File: Application.java From mq-jms-spring with Apache License 2.0 | 4 votes |
public static void main(String[] args) { // Launch the application ConfigurableApplicationContext context = SpringApplication.run(Application.class, args); // Create the JMS Template object to control connections and sessions. JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class); // Send a single message with a timestamp String msg = "Hello from IBM MQ at " + new Date(); // The default SimpleMessageConverter class will be called and turn a String // into a JMS TextMessage jmsTemplate.convertAndSend(qName, msg); status(); }
Example 12
Source File: ProductProducer.java From jim-framework with Apache License 2.0 | 4 votes |
@Override public void sendMessage(Object message) { JmsTemplate jmsTemplate= QueueJmsTemplateContainer.getJmsTemplateByQueue(Constans.QUEUE_NAME); jmsTemplate.convertAndSend(Constans.QUEUE_NAME,message); }
Example 13
Source File: SpringJmsTemplateOneWay.java From hazelcastmq with Apache License 2.0 | 4 votes |
/** * Constructs the example. */ public SpringJmsTemplateOneWay() throws InterruptedException { // Create a Hazelcast instance. Config config = new Config(); HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(config); try { // HazelcastMQ Instance HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); HazelcastMQInstance mqInstance = HazelcastMQ .newHazelcastMQInstance(mqConfig); // HazelcastMQJms Instance HazelcastMQJmsConfig mqJmsConfig = new HazelcastMQJmsConfig(); mqJmsConfig.setHazelcastMQInstance(mqInstance); HazelcastMQJmsConnectionFactory connectionFactory = new HazelcastMQJmsConnectionFactory( mqJmsConfig); // Setup the JMS Template JmsTemplate jmsOps = new JmsTemplate(connectionFactory); jmsOps.setReceiveTimeout(5000); // Send the message. jmsOps.convertAndSend("foo.bar", "Hello World"); // Simulate something interesting happening before we get around to // consuming the message. Thread.sleep(1000); // Receive the message. String msg = (String) jmsOps.receiveAndConvert("foo.bar"); log.info("Got message: " + msg); } finally { hazelcast.getLifecycleService().shutdown(); } }