Created
December 17, 2018 23:49
-
-
Save daniframos/9a855e8924bca6398cc57144a3e2da0d to your computer and use it in GitHub Desktop.
AMQ java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.caelum.camel; | |
import javax.jms.Connection; | |
import javax.jms.ConnectionFactory; | |
import javax.jms.Destination; | |
import javax.jms.JMSException; | |
import javax.jms.MessageProducer; | |
import javax.jms.Session; | |
import javax.jms.TextMessage; | |
import org.apache.activemq.ActiveMQConnection; | |
import org.apache.activemq.ActiveMQConnectionFactory; | |
import org.apache.camel.CamelContext; | |
import org.apache.camel.impl.DefaultCamelContext; | |
public class RotaPedidos { | |
private static String url = ActiveMQConnection.DEFAULT_BROKER_URL; | |
private static String subject = "TextQueue"; | |
public static void main(String args[]) throws Exception { | |
// START SNIPPET: e1 | |
CamelContext context = new DefaultCamelContext(); | |
// END SNIPPET: e1 | |
// Set up the ActiveMQ JMS Components | |
// START SNIPPET: e2 | |
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); | |
Connection connection = connectionFactory.createConnection(); | |
connection.start(); | |
//Creating a non transactional session to send/receive JMS message. | |
Session session = connection.createSession(false, | |
Session.AUTO_ACKNOWLEDGE); | |
//Destination represents here our queue 'JCG_QUEUE' on the JMS server. | |
//The queue will be created automatically on the server. | |
Destination destination = session.createQueue(subject); | |
// MessageProducer is used for sending messages to the queue. | |
MessageProducer producer = session.createProducer(destination); | |
// We will send a small text message saying 'Hello World!!!' | |
TextMessage message = session | |
.createTextMessage("Hello !!! Welcome to the world of ActiveMQ."); | |
// Here we are sending our message! | |
producer.send(message); | |
System.out.println("JCG printing@@ '" + message.getText() + "'"); | |
// END SNIPPET: e4 | |
// Now everything is set up - lets start the context | |
context.start(); | |
// wait a bit and then stop | |
Thread.sleep(1000); | |
context.stop(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>br.com.caelum</groupId> | |
<artifactId>camel-alura</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<name>projeto-camel-alura</name> | |
<url>http://maven.apache.org</url> | |
<properties> | |
<camel-version>2.16.0</camel-version> | |
</properties> | |
<repositories> | |
</repositories> | |
<dependencies> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-sql</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.activemq</groupId> | |
<artifactId>activemq-all</artifactId> | |
<version>5.11.0.redhat-630371</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-core</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-xmljson</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>xom</groupId> | |
<artifactId>xom</artifactId> | |
<version>1.2.5</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-http4</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.activemq</groupId> | |
<artifactId>activemq-camel</artifactId> | |
<version>5.6.0</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-jms</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.logging.log4j</groupId> | |
<artifactId>log4j-api</artifactId> | |
<version>2.4</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.logging.log4j</groupId> | |
<artifactId>log4j-core</artifactId> | |
<version>2.4</version> | |
</dependency> | |
<dependency> | |
<groupId>org.slf4j</groupId> | |
<artifactId>slf4j-api</artifactId> | |
<version>1.7.12</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.logging.log4j</groupId> | |
<artifactId>log4j-slf4j-impl</artifactId> | |
<version>2.4</version> | |
</dependency> | |
<!-- <dependency> --> | |
<!-- <groupId>org.apache.camel</groupId> --> | |
<!-- <artifactId>camel-sql</artifactId> --> | |
<!-- <version>${camel-version}</version> --> | |
<!-- </dependency> --> | |
<!-- <dependency> --> | |
<!-- <groupId>mysql</groupId> --> | |
<!-- <artifactId>mysql-connector-java</artifactId> --> | |
<!-- <version>5.1.36</version> --> | |
<!-- </dependency> --> | |
</dependencies> | |
<build> | |
<finalName>projeto-camel-alura</finalName> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<configuration> | |
<source>1.8</source> | |
<target>1.8</target> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment