-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOutboundAdapter.cls
84 lines (73 loc) · 1.93 KB
/
OutboundAdapter.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Class isc.rabbitmq.OutboundAdapter Extends (Ens.OutboundAdapter, isc.rabbitmq.Common)
{
/// Establish gateway connection and init java API.
Method OnInit() As %Status
{
Set sc = $$$OK
Quit:((..JGService="") && ((..JGHost="") || (..JGPort = ""))) $$$ERROR($$$GeneralError,"Specify JGService setting or JGHost and JGPort settings")
Quit:((..JGService'="") && '##class(Ens.Director).IsItemEnabled(..JGService)) $$$ERROR($$$GeneralError, $$$FormatText("Java Gateway Service: '%1' is down",..JGService))
Set sc = ..Connect()
Quit:$$$ISERR(sc) sc
Set sc = ..ConnectToRabbitMQ()
Quit sc
}
/// Close connection
Method OnTearDown() As %Status
{
Do ..API.close()
Quit $$$OK
}
/// Send message. message can be a string or stream.
Method SendMessage(message As %Stream.Object) As %Status
{
Set sc = $$$OK
Set stream = ##class(%Library.GlobalBinaryStream).%New()
If $isObject(message) {
If message.%IsA("%Library.GlobalBinaryStream") {
Set stream = message
} Else {
While 'message.AtEnd {
Do stream.Write(..EncodeMessageBody(message.Read($$$MaxStringLength)))
}
}
} Else {
Do stream.Write(..EncodeMessageBody(message))
}
Try {
Do ..API.sendMessage(stream)
} Catch ex {
Set sc = ..ExceptionToStatus(ex)
}
Quit sc
}
/// Send message. message can be a string or stream.
Method SendMessageToQueue(queue As %String, message As %Stream.Object) As %Status
{
Set sc = $$$OK
Set stream = ##class(%Library.GlobalBinaryStream).%New()
If $isObject(message) {
While 'message.AtEnd {
Do stream.Write(..EncodeMessageBody(message.Read($$$MaxStringLength)))
}
} Else {
Do stream.Write(..EncodeMessageBody(message))
}
Try {
Do ..API.sendMessageToQueue(queue, stream)
} Catch ex {
Set sc = ..ExceptionToStatus(ex)
}
Quit sc
}
Method EncodeMessageBody(body As %String) As %String
{
If ..Encoding '= "" {
If $isObject(body) {
// TODO streams
} Else {
Set body = $zcvt(body, "O", ..Encoding)
}
}
Quit body
}
}