4
4
5
5
import java .io .IOException ;
6
6
7
-
7
+ import java . nio . file .*;
8
8
/**
9
9
* Created by eduard on 06.10.2017.
10
10
*/
@@ -30,26 +30,23 @@ public API(String host, int port, String user, String pass, String virtualHost,
30
30
_queue = queue ;
31
31
}
32
32
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
-
45
33
public void sendMessage (byte [] msg ) throws Exception {
46
34
sendMessageToQueue (_queue , msg );
47
35
}
48
36
49
37
public void sendMessageToQueue (String queue , byte [] msg ) throws Exception {
38
+ //log(msg);
50
39
_channel .basicPublish ("" , queue , null , msg );
51
40
}
52
41
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
+
53
50
public String [] readMessageString () throws Exception {
54
51
String [] result = new String [16 ];
55
52
@@ -70,6 +67,7 @@ private GetResponse readMessage(String[] msg) throws IOException {
70
67
GetResponse response = _channel .basicGet (_queue , autoAck );
71
68
if (response == null ) {
72
69
// No message retrieved.
70
+ response = new GetResponse (null , null , new byte [0 ], 0 );
73
71
} else {
74
72
AMQP .BasicProperties props = response .getProps ();
75
73
msg [0 ] = Integer .toString (response .getBody ().length );
@@ -87,11 +85,18 @@ private GetResponse readMessage(String[] msg) throws IOException {
87
85
msg [12 ] = props .getDeliveryMode () != null ? Integer .toString (props .getDeliveryMode ()) : null ;
88
86
msg [13 ] = props .getPriority () != null ? Integer .toString (props .getPriority ()) : null ;
89
87
msg [14 ] = props .getTimestamp () != null ? props .getTimestamp ().toString () : null ;
88
+
89
+ //log(response.getBody());
90
90
}
91
91
return response ;
92
92
93
93
}
94
94
95
+ private void log (byte [] msg ) throws IOException {
96
+ Path path = Paths .get ("C:\\ InterSystems\\ java.log" );
97
+ Files .write (path , msg );
98
+ }
99
+
95
100
public void close ()throws Exception {
96
101
_channel .close ();
97
102
_connection .close ();
0 commit comments