@@ -45,8 +45,18 @@ Property Encoding As %String;
4545/// See property AdditionalPaths in that class.
4646Property ClassPath As %String (MAXLEN = 32000 );
4747
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+
4858/// 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 " ;
5060
5161/// Connect to running JGW
5262Method Connect () As %Status
@@ -87,14 +97,44 @@ Method ConnectToRabbitMQ() As %Status
8797 Set pass = " guest"
8898 }
8999
100+ Set port = $select (..Port =" " :-1 , 1 :..Port )
101+
90102 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 )
92104 } Catch ex {
93105 Set sc = $$$ADDSC(ex .AsStatus (),$g (%objlasterror ))
94106 }
95107
96108 Quit sc
97109}
98110
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+
99139}
100140
0 commit comments