Skip to content

Commit e0718a5

Browse files
authored
Update README.md
1 parent fca0406 commit e0718a5

File tree

1 file changed

+130
-6
lines changed

1 file changed

+130
-6
lines changed

README.md

Lines changed: 130 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,152 @@ Development is done on [Cache-Tort-Git UDL fork](https://github.com/MakarovS96/c
3030
3131
Check `RabbitMQ.Utils` for sample code. The main class is `isc.rabbitmq.API`. It has the following methods.
3232
33+
### Methods
34+
3335
| Method | Arguments | Returns | Description |
3436
|--------------------|-----------------------------------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------|
35-
| %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 |
3638
| sendMessage | msg, correlationId, messageId | null | Sends message to default queue (as specified in %OnNew) |
3739
| 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 |
4042
| close | - | - | Closes the connection |
4143
42-
Arguments:
44+
### Arguments
4345
4446
| Argument | Java type | InterSystems type | Value | Required | Description |
4547
|---------------|------------------|---------------------|---------------|-----------------------------------------------|-----------------------------------------|
48+
| gateway | - | %Net.Remote.Gateway | - | Yes | Connection to Java Gateway |
4649
| host | String | %String | localhost | Yes | Address of RabbitMQ server |
4750
| port | int | %Integer | -1 | Yes | RabbitMQ listener port |
4851
| user | String | %String | guest | Yes | Username |
4952
| pass | String | %String | guest | Yes | Password |
5053
| virtualHost | String | %String | / | Yes | Virtual host |
5154
| queue | String | %String | Test | Yes | Queue name |
5255
| 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 |
5457
| correlationId | String | %String | CorrelationId | Required only with messageId | Correlation identifier |
5558
| 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 |
5760
| 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.
161+
162+
#### Props
163+
164+
| Position | Name | Description |
165+
|----------|-----------------|---------------------------------------------------------------|
166+
| 1 | Message Length | Length of a current message |
167+
| 2 | Message Count | Number of remaining messages |
168+
| 3 | ContentType | |
169+
| 4 | ContentEncoding | |
170+
| 5 | CorrelationId | |
171+
| 6 | ReplyTo | |
172+
| 7 | Expiration | |
173+
| 8 | MessageId | |
174+
| 9 | Type | |
175+
| 10 | UserId | |
176+
| 11 | AppId | |
177+
| 12 | ClusterId | |
178+
| 13 | DeliveryMode | |
179+
| 14 | Priority | |
180+
| 15 | Timestamp | |
181+
| 16 | Message body | If message is read as a string, this element would contain it |

0 commit comments

Comments
 (0)