Skip to content

Commit 043505c

Browse files
committed
Create Active MQ project in git
0 parents  commit 043505c

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed

activemq/pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.jms.activemq</groupId>
5+
<artifactId>activemq_tutorial</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<dependencies>
8+
<dependency>
9+
<groupId>org.apache.activemq</groupId>
10+
<artifactId>activemq-all</artifactId>
11+
<version>5.1.0</version>
12+
<scope>compile</scope>
13+
</dependency>
14+
<dependency>
15+
<groupId>org.springframework</groupId>
16+
<artifactId>spring-jms</artifactId>
17+
<version>3.1.0.RELEASE</version>
18+
<scope>compile</scope>
19+
</dependency>
20+
<dependency>
21+
<groupId>log4j</groupId>
22+
<artifactId>log4j</artifactId>
23+
<version>1.2.16</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.slf4j</groupId>
27+
<artifactId>slf4j-log4j12</artifactId>
28+
<version>1.6.4</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>commons-pool</groupId>
32+
<artifactId>commons-pool</artifactId>
33+
<version>1.5.7</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.apache.geronimo.specs</groupId>
37+
<artifactId>geronimo-jta_1.1_spec</artifactId>
38+
<version>1.1.1</version>
39+
</dependency>
40+
</dependencies>
41+
</project>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.test.first.queue;
2+
3+
import javax.jms.Connection;
4+
import javax.jms.ConnectionFactory;
5+
import javax.jms.Destination;
6+
import javax.jms.JMSException;
7+
import javax.jms.Message;
8+
import javax.jms.MessageConsumer;
9+
import javax.jms.Session;
10+
import javax.jms.TextMessage;
11+
import org.apache.activemq.ActiveMQConnection;
12+
import org.apache.activemq.ActiveMQConnectionFactory;
13+
14+
15+
/**
16+
*
17+
* @author Deepak.Keswani
18+
* Simple Receiver
19+
*/
20+
21+
public class Receiver {
22+
23+
private ConnectionFactory factory = null;
24+
private Connection connection = null;
25+
private Session session = null;
26+
private Destination destination = null;
27+
private MessageConsumer consumer = null;
28+
29+
public void receiveMessage() {
30+
try {
31+
factory = new ActiveMQConnectionFactory(
32+
ActiveMQConnection.DEFAULT_BROKER_URL);
33+
connection = factory.createConnection();
34+
connection.start();
35+
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
36+
destination = session.createQueue("SAMPLEQUEUE");
37+
consumer = session.createConsumer(destination);
38+
System.out.println("b4 receive");
39+
Message message = consumer.receive();
40+
System.out.println("after receive");
41+
if(message instanceof TextMessage){
42+
TextMessage textMessage = (TextMessage)message;
43+
System.out.println("Received message is -----------> " + textMessage.getText());
44+
}
45+
} catch (JMSException e) {
46+
// TODO Auto-generated catch block
47+
e.printStackTrace();
48+
}finally{
49+
try{
50+
session.close();
51+
connection.close();
52+
}catch (JMSException e) {
53+
// TODO Auto-generated catch block
54+
e.printStackTrace();
55+
}
56+
}
57+
58+
}
59+
60+
public static void main(String[] args) {
61+
Receiver reciever = new Receiver();
62+
reciever.receiveMessage();
63+
}
64+
65+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.test.first.queue;
2+
3+
import javax.jms.Connection;
4+
import javax.jms.ConnectionFactory;
5+
import javax.jms.Destination;
6+
import javax.jms.JMSException;
7+
import javax.jms.MessageProducer;
8+
import javax.jms.Session;
9+
import javax.jms.TextMessage;
10+
11+
import org.apache.activemq.ActiveMQConnection;
12+
import org.apache.activemq.ActiveMQConnectionFactory;
13+
14+
15+
/**
16+
*
17+
* @author Deepak.Keswani
18+
*
19+
*/
20+
public class Sender {
21+
22+
private ConnectionFactory factory = null;
23+
private Connection connection = null;
24+
25+
private Session session = null;
26+
27+
private Destination destination = null;
28+
29+
private MessageProducer producer = null;
30+
31+
public void sendMessage() {
32+
try {
33+
factory = new ActiveMQConnectionFactory(
34+
ActiveMQConnection.DEFAULT_BROKER_URL);
35+
connection = factory.createConnection();
36+
connection.start();
37+
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
38+
destination = session.createQueue("SAMPLEQUEUE");
39+
producer = session.createProducer(destination);
40+
TextMessage message = session.createTextMessage();
41+
message.setText("Hello ...This is a sample message..sending from FirstClient");
42+
producer.send(message);
43+
System.out.println("Sent: " + message.getText());
44+
} catch (JMSException e) {
45+
// TODO Auto-generated catch block
46+
e.printStackTrace();
47+
}finally{
48+
try{
49+
session.close();
50+
connection.close();
51+
}catch (JMSException e) {
52+
// TODO Auto-generated catch block
53+
e.printStackTrace();
54+
}
55+
}
56+
}
57+
58+
public static void main(String args[]) {
59+
Sender sender = new Sender();
60+
sender.sendMessage();
61+
}
62+
63+
}

0 commit comments

Comments
 (0)