Skip to content

Commit

Permalink
Better stream handing
Browse files Browse the repository at this point in the history
  • Loading branch information
eduard93 committed Oct 11, 2017
1 parent fc4e389 commit 8d39086
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/isc/rabbitmq/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.io.IOException;


import java.nio.file.*;
/**
* Created by eduard on 06.10.2017.
*/
Expand All @@ -30,26 +30,23 @@ public API(String host, int port, String user, String pass, String virtualHost,
_queue = queue;
}

public String[] readMessageStream(byte[] msg) throws Exception {
String[] result = new String[15];

GetResponse response = readMessage(result);
if (response == null) {
// No message retrieved.
} else {
System.arraycopy(response.getBody(),0,msg,0, response.getBody().length);
}
return result;
}

public void sendMessage(byte[] msg) throws Exception {
sendMessageToQueue(_queue, msg);
}

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

public byte[] readMessageStream(String[] result) throws Exception {
GetResponse response = readMessage(result);
if (response == null) {
return new byte[0];
}
return response.getBody();
}

public String[] readMessageString() throws Exception {
String[] result = new String[16];

Expand All @@ -70,6 +67,7 @@ private GetResponse readMessage(String[] msg) throws IOException {
GetResponse response = _channel.basicGet(_queue, autoAck);
if (response == null) {
// No message retrieved.
response = new GetResponse(null, null, new byte[0], 0);
} else {
AMQP.BasicProperties props = response.getProps();
msg[0] = Integer.toString(response.getBody().length);
Expand All @@ -87,11 +85,18 @@ private GetResponse readMessage(String[] msg) throws IOException {
msg[12] = props.getDeliveryMode() != null ? Integer.toString(props.getDeliveryMode()) : null;
msg[13] = props.getPriority() != null ? Integer.toString(props.getPriority()) : null;
msg[14] = props.getTimestamp() != null ? props.getTimestamp().toString() : null;

//log(response.getBody());
}
return response;

}

private void log(byte[] msg) throws IOException {
Path path = Paths.get("C:\\InterSystems\\java.log");
Files.write(path, msg);
}

public void close()throws Exception {
_channel.close();
_connection.close();
Expand Down

0 comments on commit 8d39086

Please sign in to comment.