You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| %OnNew | host, port, user, pass, virtualHost, queue, durable | api | Creates new connection to RabbitMQ |
37
+
| %OnNew | gateway, host, port, user, pass, virtualHost, queue, durable | api | Creates new connection to RabbitMQ |
36
38
| sendMessage | msg, correlationId, messageId | null | Sends message to default queue (as specified in %OnNew) |
37
39
| sendMessageToQueue | queue, msg, correlationId, messageId | null | Sends message to the specified queue |
38
-
| readMessageString | - | result | Reads message from default queue. Returns list of message properties (including message text) |
39
-
| readMessageStream | result | msg | Reads message from default queue. Returns message text as array and result - is populated with a list of message properties |
40
+
| readMessageString | - | props | Reads message from default queue. Returns list of message properties (including message text) |
41
+
| readMessageStream | props| msg | Reads message from default queue. Returns message text as a stream and props is populated with a list of message properties |
40
42
| close | - | - | Closes the connection |
41
43
42
-
Arguments:
44
+
### Arguments
43
45
44
46
| Argument | Java type | InterSystems type | Value | Required | Description |
| queue | String | %String | Test | Yes | Queue name |
52
55
| durable | int | %Integer | 1 | Required only if you want to create new queue | The queue will survive a server restart |
53
-
| msg | byte[] | %GlobalBinaryStream | Text | Yes as argument | Message body |
56
+
| msg | byte[] | %GlobalBinaryStream | Text | Yes | Message body |
54
57
| correlationId | String | %String | CorrelationId | Required only with messageId | Correlation identifier |
55
58
| messageId | String | %String | MessageId | Required only with correlationId | Message identifier |
56
-
| result | String[] | %ListOfDataTypes | - | Yes as argument. Should have 16 elements | List of message properties |
59
+
| props| String[] | %ListOfDataTypes | - | Yes. Should have 15 elements | List of message properties |
57
60
| api | isc.rabbitmq.API | isc.rabbitmq.API | - | - | API object |
61
+
62
+
### Initialization
63
+
64
+
#### Java Gateway
65
+
66
+
First you need a Java Gateway object (hereinafter: `gateway`). For example you can get it using this method:
67
+
68
+
```
69
+
/// Get JGW object
70
+
ClassMethod Connect(gatewayName As %String, path As %String, Output sc As %Status) As %Net.Remote.Gateway
71
+
{
72
+
Set gateway = ""
73
+
Set sc = ##class(%Net.Remote.Service).OpenGateway(gatewayName, .gatewayConfig)
74
+
Quit:$$$ISERR(sc) gateway
75
+
Set sc = ##class(%Net.Remote.Service).ConnectGateway(gatewayConfig, .gateway, path, $$$YES)
76
+
Quit gateway
77
+
}
78
+
```
79
+
Where:
80
+
- gatewayName - is name of Java Gateway (it would be started automatically)
81
+
- path - path to [JAR](https://github.com/intersystems-ru/RabbitMQ-Ensemble-javaapi/releases)
82
+
83
+
#### RabbitMQ
84
+
85
+
Now that Java Gateway connection is established we can connect to RabbitMQ:
86
+
87
+
```
88
+
ClassMethod GetAPI(gateway As %Net.Remote.Gateway) As isc.rabbitmq.API
89
+
{
90
+
Set host = "localhost"
91
+
Set port = -1
92
+
Set user = "guest"
93
+
Set pass = "guest"
94
+
Set virtualHost = "/"
95
+
Set queue = "Test"
96
+
Set durable = $$$YES
97
+
98
+
Set api = ##class(isc.rabbitmq.API).%New(gateway, host, port, user, pass, virtualHost, queue, durable)
99
+
Quit api
100
+
}
101
+
```
102
+
103
+
All parameters are described in the table above. Note that `durable` argument is used only if you're creating a new queue. If the queue alreay exists you should still provide it (0 or 1) but it won't be used.
104
+
105
+
### Sending messages
106
+
107
+
Assuming you already have `api` object, sending messages can be done by one of two ways:
108
+
- sending messages to default queue
109
+
- sending messages to specified queue
110
+
111
+
#### Sending messages to default queue
112
+
113
+
Default queue is a queue specified during creation of the `api` object. To send a message just call
114
+
115
+
```
116
+
#Dim api As isc.rabbitmq.API
117
+
#Dim msg As %GlobalBinaryStream
118
+
Do api.sendMessage(msg, "correlationId", "messageId " _ $zdt($zts,3,1,3))
119
+
```
120
+
121
+
Where `stream` is a message body. You can either provide both `messageId` and `correlationId` or non of them.
122
+
123
+
#### Sending messages to specified queue
124
+
125
+
Everything is the same as above, except you call `sendMessageToQueue` method and the first argument is the name of the queue.
126
+
127
+
### Reading messages
128
+
129
+
Messages are always read from the default queue (specified at creation of the `api` object). Message body can be received as text or as a stream.
130
+
131
+
132
+
`props` should have 15 elements in the case message mody would be returned as a stream, and 16 if it would be returned as a string. In that case 16th element would be message body.
133
+
134
+
#### Reading message as a stream
135
+
136
+
First you need to prepare `props` to pass by reference into Java and then call `readMessageStream`:
137
+
138
+
```
139
+
#Dim api As isc.rabbitmq.API
140
+
#Dim msg As %GlobalBinaryStream
141
+
#Dim props As %ListOfDataTypes
142
+
Set props = ##class(%ListOfDataTypes).%New()
143
+
For i=1:1:15 Do props.Insert("")
144
+
Set msg = api.readMessageStream(.props)
145
+
```
146
+
147
+
`props` would be filled with message metainformation, and `msg` is a stream containig message body.
148
+
149
+
150
+
#### Reading message as a string
151
+
152
+
153
+
```
154
+
#Dim api As isc.rabbitmq.API
155
+
#Dim msg As %GlobalBinaryStream
156
+
#Dim props As %ListOfDataTypes
157
+
Set props = api.readMessageString()
158
+
```
159
+
160
+
`props` would be filled with message metainformation, not that you don't need to init it on InterSystems side before calling RabbitMQ.
0 commit comments