@@ -45,8 +45,18 @@ Property Encoding As %String;
45
45
/// See property AdditionalPaths in that class.
46
46
Property ClassPath As %String (MAXLEN = 32000 );
47
47
48
+ /// How many times have we tried reconnecting
49
+ /// empty - do not retry
50
+ /// 0 - retry ad infinitum
51
+ /// n - retry n times
52
+ Property RetryCount As %Integer [ InitialExpression = 5 ];
53
+
54
+ /// How frequently to retry access to the output system.
55
+ /// Pause in seconds between retry attempts.
56
+ Property RetryInterval As %Numeric (MINVAL = 0 ) [ InitialExpression = 5 ];
57
+
48
58
/// These are the production settings for this object
49
- Parameter SETTINGS = " Host:Basic,Port:Basic,VirtualHost:Basic,Queue:Basic,Credentials:Basic:credentialsSelector,JGHost:Java Gateway,JGPort:Java Gateway,JGService:Java Gateway:selector?context={Ens.ContextSearch/ProductionItems?targets=0&productionName=@productionId},ClassPath:Basic,Encoding:Basic" ;
59
+ Parameter SETTINGS = " Host:Basic,Port:Basic,VirtualHost:Basic,Queue:Basic,Credentials:Basic:credentialsSelector,JGHost:Java Gateway,JGPort:Java Gateway,JGService:Java Gateway:selector?context={Ens.ContextSearch/ProductionItems?targets=0&productionName=@productionId},ClassPath:Basic,Encoding:Basic,RetryCount:Alerting,RetryInterval:Alerting " ;
50
60
51
61
/// Connect to running JGW
52
62
Method Connect () As %Status
@@ -87,14 +97,44 @@ Method ConnectToRabbitMQ() As %Status
87
97
Set pass = " guest"
88
98
}
89
99
100
+ Set port = $select (..Port =" " :-1 , 1 :..Port )
101
+
90
102
Try {
91
- Set ..API = ##class (isc.rabbitmq.API ).%New (..JGW , ..Host , .. Port , user , pass , ..VirtualHost , ..Queue , $$$YES, ..Exchange )
103
+ Set ..API = ##class (isc.rabbitmq.API ).%New (..JGW , ..Host , port , user , pass , ..VirtualHost , ..Queue , $$$YES, ..Exchange )
92
104
} Catch ex {
93
105
Set sc = $$$ADDSC(ex .AsStatus (),$g (%objlasterror ))
94
106
}
95
107
96
108
Quit sc
97
109
}
98
110
111
+ Method IsOpen () As %Status
112
+ {
113
+ #Dim sc As %Status = $$$OK
114
+ Set retryCount = 1
115
+ Try {
116
+ While '..API .isOpen () {
117
+ If ..RetryCount = " " {
118
+ Set sc = $$$ERROR($$$GeneralError, " Connection problems. Consider specifying RetryCount and RetryInterval settings" )
119
+ } ElseIf ((..RetryCount = 0 ) || (retryCount < ..RetryCount )) {
120
+ // wait and retry connecting
121
+ Set retryCount = retryCount + 1
122
+ Hang ..RetryInterval
123
+
124
+ // reconnect happens in isOpen method
125
+ } Else {
126
+ // we're out of reconnect attempts
127
+ Set sc = $$$ERROR($$$GeneralError, $$$FormatText(" Connection still closed after %1 attempts at reconnecting." , ..RetryCount ))
128
+ }
129
+ Quit :$$$ISERR(sc )
130
+ }
131
+ } Catch ex {
132
+ #Dim ex As %Exception.General
133
+ Set sc = ex .AsStatus ()
134
+ }
135
+
136
+ Quit sc
137
+ }
138
+
99
139
}
100
140
0 commit comments