Skip to content

Commit 8f55d09

Browse files
committed
Added optional message properties: correlationId, messageId
For #1
1 parent 8d39086 commit 8f55d09

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/isc/rabbitmq/API.java

+33
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import java.io.IOException;
66

77
import java.nio.file.*;
8+
9+
import java.util.Date;
10+
import java.util.HashMap;
11+
812
/**
913
* Created by eduard on 06.10.2017.
1014
*/
@@ -30,6 +34,10 @@ public API(String host, int port, String user, String pass, String virtualHost,
3034
_queue = queue;
3135
}
3236

37+
public void sendMessage(byte[] msg, String correlationId, String messageId) throws Exception {
38+
sendMessageToQueue(_queue, msg, correlationId, messageId);
39+
}
40+
3341
public void sendMessage(byte[] msg) throws Exception {
3442
sendMessageToQueue(_queue, msg);
3543
}
@@ -39,6 +47,11 @@ public void sendMessageToQueue(String queue, byte[] msg) throws Exception {
3947
_channel.basicPublish("", queue, null, msg);
4048
}
4149

50+
public void sendMessageToQueue(String queue, byte[] msg, String correlationId, String messageId) throws Exception {
51+
AMQP.BasicProperties props = createProperties(correlationId, messageId);
52+
_channel.basicPublish("", queue, props, msg);
53+
}
54+
4255
public byte[] readMessageStream(String[] result) throws Exception {
4356
GetResponse response = readMessage(result);
4457
if (response == null) {
@@ -102,4 +115,24 @@ public void close()throws Exception {
102115
_connection.close();
103116
}
104117

118+
private AMQP.BasicProperties createProperties(String correlationId, String messageId) throws Exception
119+
{
120+
String contentType = null;
121+
String contentEncoding = null;
122+
HashMap<String, Object> headers = null;
123+
Integer deliveryMode = null;
124+
Integer priority = null;
125+
//String correlationId= null;
126+
String replyTo = null;
127+
String expiration= null;
128+
//String messageId= null;
129+
Date timestamp= null;
130+
String type = null;
131+
String userId= null;
132+
String appId = null;
133+
String clusterId= null;
134+
AMQP.BasicProperties props = new AMQP.BasicProperties(contentType, contentEncoding, headers, deliveryMode, priority, correlationId, replyTo, expiration, messageId, timestamp, type, userId, appId, clusterId);
135+
return props;
136+
}
137+
105138
}

0 commit comments

Comments
 (0)