@@ -6,7 +6,7 @@ Property BodyClass As %Dictionary.CacheClassname;
66
77Parameter SETTINGS = " BodyClass:Basic" ;
88
9- /// Establish gateway connectionand init java API
9+ /// Establish gateway connection and init java API.
1010Method OnInit () As %Status
1111{
1212 Set sc = $$$OK
@@ -18,28 +18,31 @@ Method OnInit() As %Status
1818 Quit sc
1919}
2020
21- /// Close connection
21+ /// Close connection.
2222Method OnTearDown () As %Status
2323{
2424 Do ..API .close ()
2525 Quit $$$OK
2626}
2727
28- /// default InboundAdapter behavior: always call ProcessInput on CallInterval
28+ /// Get Messages from RabbitMQ queue.
2929Method OnTask () As %Status
3030{
3131 Set sc = $$$OK
3232
3333 Set messageCount = 1
3434
3535 While messageCount > 0 {
36+ // List containing metainformation and possibly body (in the case of string interaction) of the RabbitMQ message
3637 #Dim messageList As %ListOfDataTypes
3738
3839 If ..BodyClass = " " {
3940 Set messageList = ..API .readMessageString ()
4041 } Else {
41- Set tempStream = ..GetTempStream ()
42- Set messageList = ..API .readMessageStream (.tempStream )
42+ #Dim tempStream As %Library.GlobalBinaryStream
43+ Set messageList = ##class (%ListOfDataTypes ).%New ()
44+ For i =1 :1 :15 Do messageList .Insert (" " )
45+ Set tempStream = ..API .readMessageStream (.messageList )
4346 }
4447
4548 Set messageLength = messageList .GetAt (1 )
@@ -49,11 +52,13 @@ Method OnTask() As %Status
4952 #Dim message As RabbitMQ.Message
5053 Set message = ..ListToMessage (messageList )
5154 If ..BodyClass = " " {
52- Set message .Body = ..DecodeMessageBody (messageList .GetAt (16 ))
55+ Set message .BodyString = ..DecodeMessageBody (messageList .GetAt (16 ))
5356 } Else {
54- Set message .Body = $classmethod (..BodyClass , " %New" )
55- Do message .Body .Write (..DecodeMessageBody (tempStream .Read (messageLength )))
56- Do message .Body .Rewind ()
57+ Set message .BodyStream = $classmethod (..BodyClass , " %New" )
58+ While 'tempStream .AtEnd {
59+ Do message .BodyStream .Write (..DecodeMessageBody (tempStream .Read ($$$MaxStringLength)))
60+ }
61+ Do message .BodyStream .Rewind ()
5762 }
5863 Set sc = ..BusinessHost .ProcessInput (message )
5964 } Else {
@@ -65,6 +70,7 @@ Method OnTask() As %Status
6570 Quit sc
6671}
6772
73+ /// Convert list containing metainformation into RabbitMQ message
6874ClassMethod ListToMessage (list As %ListOfDataTypes ) As RabbitMQ .Message
6975{
7076 Set message = ##class (RabbitMQ.Message ).%New ()
@@ -86,27 +92,12 @@ ClassMethod ListToMessage(list As %ListOfDataTypes) As RabbitMQ.Message
8692 Quit message
8793}
8894
95+ /// Decode message body. May be full body or only a piece.
8996Method DecodeMessageBody (body As %String ) As %String
9097{
91- If ..Encoding '= " " {
92- If $isObject (body ) {
93- // TODO streams
94- } Else {
95- Set body = $zcvt (body , " O" , ..Encoding )
96- }
97- }
98+ Set :..Encoding '=" " body = $zcvt (body , " O" , ..Encoding )
9899 Quit body
99100}
100101
101- ClassMethod GetTempStream () As %GlobalBinaryStream
102- {
103- Set stream =##class (%GlobalBinaryStream ).%New ()
104- // TODO - work around that
105- // we need to 'reserve' a number of bytes since we are passing the stream
106- // by reference (Java's equivalent is byte[] ba = new byte[max];)
107- For i =1 :1 :32000 Do stream .Write (" 0" )
108- Quit stream
109- }
110-
111102}
112103
0 commit comments