Skip to content

Commit 6398558

Browse files
committed
Apache Kafka producer & consumer
1 parent 3ae1a76 commit 6398558

File tree

356 files changed

+12252
-9716
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

356 files changed

+12252
-9716
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
1-
package com.app.message;
2-
3-
import java.io.Serializable;
4-
import java.util.ArrayList;
5-
import java.util.List;
6-
import java.util.Map;
7-
8-
9-
public class MyMessage implements Serializable{
10-
11-
12-
13-
private static final long serialVersionUID = 1L;
14-
15-
16-
private Integer id;
17-
private String name;
18-
private List<String> roles = new ArrayList<>();;
19-
private Map<String,Double> depSal;
20-
21-
22-
public MyMessage() {
23-
super();
24-
}
25-
26-
public MyMessage(Integer id, String name, List<String> roles, Map<String, Double> depSal) {
27-
super();
28-
this.id = id;
29-
this.name = name;
30-
this.roles = roles;
31-
this.depSal = depSal;
32-
}
33-
34-
public Integer getId() {
35-
return id;
36-
}
37-
38-
public void setId(Integer id) {
39-
this.id = id;
40-
}
41-
42-
public String getName() {
43-
return name;
44-
}
45-
46-
public void setName(String name) {
47-
this.name = name;
48-
}
49-
50-
public List<String> getRoles() {
51-
return roles;
52-
}
53-
54-
public void setRoles(List<String> roles) {
55-
this.roles = roles;
56-
}
57-
58-
public Map<String, Double> getDepSal() {
59-
return depSal;
60-
}
61-
62-
public void setDepSal(Map<String, Double> depSal) {
63-
this.depSal = depSal;
64-
}
65-
66-
@Override
67-
public String toString() {
68-
return "MyMessage [id=" + id + ", name=" + name + ", roles=" + roles + ", depSal=" + depSal + "]";
69-
}
70-
71-
72-
73-
}
1+
package com.app.message;
2+
3+
import java.io.Serializable;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
9+
public class MyMessage implements Serializable{
10+
11+
12+
13+
private static final long serialVersionUID = 1L;
14+
15+
16+
private Integer id;
17+
private String name;
18+
private List<String> roles = new ArrayList<>();;
19+
private Map<String,Double> depSal;
20+
21+
22+
public MyMessage() {
23+
super();
24+
}
25+
26+
public MyMessage(Integer id, String name, List<String> roles, Map<String, Double> depSal) {
27+
super();
28+
this.id = id;
29+
this.name = name;
30+
this.roles = roles;
31+
this.depSal = depSal;
32+
}
33+
34+
public Integer getId() {
35+
return id;
36+
}
37+
38+
public void setId(Integer id) {
39+
this.id = id;
40+
}
41+
42+
public String getName() {
43+
return name;
44+
}
45+
46+
public void setName(String name) {
47+
this.name = name;
48+
}
49+
50+
public List<String> getRoles() {
51+
return roles;
52+
}
53+
54+
public void setRoles(List<String> roles) {
55+
this.roles = roles;
56+
}
57+
58+
public Map<String, Double> getDepSal() {
59+
return depSal;
60+
}
61+
62+
public void setDepSal(Map<String, Double> depSal) {
63+
this.depSal = depSal;
64+
}
65+
66+
@Override
67+
public String toString() {
68+
return "MyMessage [id=" + id + ", name=" + name + ", roles=" + roles + ", depSal=" + depSal + "]";
69+
}
70+
71+
72+
73+
}
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
1-
package com.app.reciever;
2-
3-
import javax.jms.JMSException;
4-
import javax.jms.Message;
5-
import javax.jms.ObjectMessage;
6-
import javax.jms.TextMessage;
7-
8-
import org.springframework.jms.annotation.JmsListener;
9-
import org.springframework.stereotype.Component;
10-
11-
import com.app.message.MyMessage;
12-
13-
/**
14-
* P2P :- Send Message from one producer to one consumer . It store messages in destination memory called Queue .
15-
*
16-
* Produces :- It uses JmsTemplate to send message to consumer.
17-
*
18-
* @EnableJms :- Use at starter class level for configuration .
19-
*
20-
* @JmsListener(destination = "...") :- use at method level to specify destination memory name .
21-
*
22-
* javax.jms.Message (I) :- Root interfcae for all Jms Messages (Text and Object Both)
23-
*
24-
* Then cast it to TextMessage type for TextMessage and ObjectMessege for Serialized Object
25-
*
26-
* For sending Object , the object must be serializable .
27-
*
28-
* ---> Object must be serialized and serialversionUid must be same .
29-
*
30-
* --> In properties file specify spring.activemq.packages.trust-all -- to trust all classes in Deserialization
31-
*
32-
*
33-
* **/
34-
35-
36-
37-
38-
@Component
39-
public class MyMessageReader {
40-
41-
@JmsListener(destination = "my-p2p-text")
42-
public void readTextMessage(Message m) // javax.jms.Message -- root interface for all messages to recieve all type of messeges
43-
{
44-
TextMessage tm = (TextMessage) m; // for text message
45-
46-
try {
47-
String msg = tm.getText();
48-
49-
System.out.println("From Consumer "+msg);
50-
51-
} catch (JMSException e) {
52-
e.printStackTrace();
53-
}
54-
55-
System.out.println("done text message");
56-
57-
}
58-
59-
60-
@JmsListener(destination = "my-p2p-object")
61-
public void readObjectMessage(Message m)
62-
{
63-
ObjectMessage om = (ObjectMessage) m; // for Object that must be Serialized
64-
65-
66-
try {
67-
MyMessage msg = (MyMessage) om.getObject();
68-
69-
System.out.println(msg);
70-
71-
} catch (JMSException e) {
72-
e.printStackTrace();
73-
}
74-
75-
System.out.println("done object message");
76-
77-
}
78-
79-
80-
}
1+
package com.app.reciever;
2+
3+
import javax.jms.JMSException;
4+
import javax.jms.Message;
5+
import javax.jms.ObjectMessage;
6+
import javax.jms.TextMessage;
7+
8+
import org.springframework.jms.annotation.JmsListener;
9+
import org.springframework.stereotype.Component;
10+
11+
import com.app.message.MyMessage;
12+
13+
/**
14+
* P2P :- Send Message from one producer to one consumer . It store messages in destination memory called Queue .
15+
*
16+
* Produces :- It uses JmsTemplate to send message to consumer.
17+
*
18+
* @EnableJms :- Use at starter class level for configuration .
19+
*
20+
* @JmsListener(destination = "...") :- use at method level to specify destination memory name .
21+
*
22+
* javax.jms.Message (I) :- Root interfcae for all Jms Messages (Text and Object Both)
23+
*
24+
* Then cast it to TextMessage type for TextMessage and ObjectMessege for Serialized Object
25+
*
26+
* For sending Object , the object must be serializable .
27+
*
28+
* ---> Object must be serialized and serialversionUid must be same .
29+
*
30+
* --> In properties file specify spring.activemq.packages.trust-all -- to trust all classes in Deserialization
31+
*
32+
*
33+
* **/
34+
35+
36+
37+
38+
@Component
39+
public class MyMessageReader {
40+
41+
@JmsListener(destination = "my-p2p-text")
42+
public void readTextMessage(Message m) // javax.jms.Message -- root interface for all messages to recieve all type of messeges
43+
{
44+
TextMessage tm = (TextMessage) m; // for text message
45+
46+
try {
47+
String msg = tm.getText();
48+
49+
System.out.println("From Consumer "+msg);
50+
51+
} catch (JMSException e) {
52+
e.printStackTrace();
53+
}
54+
55+
System.out.println("done text message");
56+
57+
}
58+
59+
60+
@JmsListener(destination = "my-p2p-object")
61+
public void readObjectMessage(Message m)
62+
{
63+
ObjectMessage om = (ObjectMessage) m; // for Object that must be Serialized
64+
65+
66+
try {
67+
MyMessage msg = (MyMessage) om.getObject();
68+
69+
System.out.println(msg);
70+
71+
} catch (JMSException e) {
72+
e.printStackTrace();
73+
}
74+
75+
System.out.println("done object message");
76+
77+
}
78+
79+
80+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Manifest-Version: 1.0
2-
Implementation-Title: ActiveMQ-P2P-Consumer
3-
Implementation-Version: 0.0.1-SNAPSHOT
4-
Build-Jdk-Spec: 1.8
5-
Created-By: Maven Integration for Eclipse
6-
1+
Manifest-Version: 1.0
2+
Implementation-Title: ActiveMQ-P2P-Consumer
3+
Implementation-Version: 0.0.1-SNAPSHOT
4+
Build-Jdk-Spec: 1.8
5+
Created-By: Maven Integration for Eclipse
6+
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#Generated by Maven Integration for Eclipse
2-
#Tue Aug 20 10:55:06 IST 2019
3-
version=0.0.1-SNAPSHOT
4-
groupId=com.app
5-
m2e.projectName=ActiveMQ-P2P-Consumer
6-
m2e.projectLocation=C\:\\Users\\The_Incredible_Srv\\Documents\\spring\\springBoot\\MessageQueue\\ActiveMQ-P2P-Consumer
7-
artifactId=ActiveMQ-P2P-Consumer
1+
#Generated by Maven Integration for Eclipse
2+
#Tue Aug 20 10:55:06 IST 2019
3+
version=0.0.1-SNAPSHOT
4+
groupId=com.app
5+
m2e.projectName=ActiveMQ-P2P-Consumer
6+
m2e.projectLocation=C\:\\Users\\The_Incredible_Srv\\Documents\\spring\\springBoot\\MessageQueue\\ActiveMQ-P2P-Consumer
7+
artifactId=ActiveMQ-P2P-Consumer

0 commit comments

Comments
 (0)