Skip to content

Commit 8d39086

Browse files
committedOct 11, 2017
Better stream handing
1 parent fc4e389 commit 8d39086

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed
 

Diff for: ‎src/isc/rabbitmq/API.java

+18-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import java.io.IOException;
66

7-
7+
import java.nio.file.*;
88
/**
99
* Created by eduard on 06.10.2017.
1010
*/
@@ -30,26 +30,23 @@ public API(String host, int port, String user, String pass, String virtualHost,
3030
_queue = queue;
3131
}
3232

33-
public String[] readMessageStream(byte[] msg) throws Exception {
34-
String[] result = new String[15];
35-
36-
GetResponse response = readMessage(result);
37-
if (response == null) {
38-
// No message retrieved.
39-
} else {
40-
System.arraycopy(response.getBody(),0,msg,0, response.getBody().length);
41-
}
42-
return result;
43-
}
44-
4533
public void sendMessage(byte[] msg) throws Exception {
4634
sendMessageToQueue(_queue, msg);
4735
}
4836

4937
public void sendMessageToQueue(String queue, byte[] msg) throws Exception {
38+
//log(msg);
5039
_channel.basicPublish("", queue, null, msg);
5140
}
5241

42+
public byte[] readMessageStream(String[] result) throws Exception {
43+
GetResponse response = readMessage(result);
44+
if (response == null) {
45+
return new byte[0];
46+
}
47+
return response.getBody();
48+
}
49+
5350
public String[] readMessageString() throws Exception {
5451
String[] result = new String[16];
5552

@@ -70,6 +67,7 @@ private GetResponse readMessage(String[] msg) throws IOException {
7067
GetResponse response = _channel.basicGet(_queue, autoAck);
7168
if (response == null) {
7269
// No message retrieved.
70+
response = new GetResponse(null, null, new byte[0], 0);
7371
} else {
7472
AMQP.BasicProperties props = response.getProps();
7573
msg[0] = Integer.toString(response.getBody().length);
@@ -87,11 +85,18 @@ private GetResponse readMessage(String[] msg) throws IOException {
8785
msg[12] = props.getDeliveryMode() != null ? Integer.toString(props.getDeliveryMode()) : null;
8886
msg[13] = props.getPriority() != null ? Integer.toString(props.getPriority()) : null;
8987
msg[14] = props.getTimestamp() != null ? props.getTimestamp().toString() : null;
88+
89+
//log(response.getBody());
9090
}
9191
return response;
9292

9393
}
9494

95+
private void log(byte[] msg) throws IOException {
96+
Path path = Paths.get("C:\\InterSystems\\java.log");
97+
Files.write(path, msg);
98+
}
99+
95100
public void close()throws Exception {
96101
_channel.close();
97102
_connection.close();

0 commit comments

Comments
 (0)
Please sign in to comment.