@@ -2,6 +2,7 @@ package rabbitmqamqp
22
33import (
44 "errors"
5+ "slices"
56 "sync"
67 "time"
78)
@@ -90,3 +91,159 @@ func (e *entitiesTracker) CleanUp() {
9091 return true
9192 })
9293}
94+
95+ type queueRecoveryRecord struct {
96+ queueName string
97+ queueType TQueueType
98+ autoDelete * bool
99+ exclusive * bool
100+ arguments map [string ]any
101+ }
102+
103+ func (q * queueRecoveryRecord ) toIQueueSpecification () IQueueSpecification {
104+ switch q .queueType {
105+ case Quorum :
106+ return & QuorumQueueSpecification {
107+ Name : q .queueName ,
108+ Arguments : q .arguments ,
109+ }
110+ case Classic :
111+ return & ClassicQueueSpecification {
112+ Name : q .queueName ,
113+ IsAutoDelete : * q .autoDelete ,
114+ IsExclusive : * q .exclusive ,
115+ Arguments : q .arguments ,
116+ }
117+ case Stream :
118+ return & StreamQueueSpecification {
119+ Name : q .queueName ,
120+ Arguments : q .arguments ,
121+ }
122+ }
123+ return nil
124+ }
125+
126+ type exchangeRecoveryRecord struct {
127+ exchangeName string
128+ exchangeType TExchangeType
129+ autoDelete bool
130+ arguments map [string ]any
131+ }
132+
133+ func (e * exchangeRecoveryRecord ) toIExchangeSpecification () IExchangeSpecification {
134+ switch e .exchangeType {
135+ case Direct :
136+ return & DirectExchangeSpecification {
137+ Name : e .exchangeName ,
138+ IsAutoDelete : e .autoDelete ,
139+ Arguments : e .arguments ,
140+ }
141+ case Topic :
142+ return & TopicExchangeSpecification {
143+ Name : e .exchangeName ,
144+ IsAutoDelete : e .autoDelete ,
145+ Arguments : e .arguments ,
146+ }
147+ case FanOut :
148+ return & FanOutExchangeSpecification {
149+ Name : e .exchangeName ,
150+ IsAutoDelete : e .autoDelete ,
151+ Arguments : e .arguments ,
152+ }
153+ case Headers :
154+ return & HeadersExchangeSpecification {
155+ Name : e .exchangeName ,
156+ IsAutoDelete : e .autoDelete ,
157+ Arguments : e .arguments ,
158+ }
159+ default :
160+ return & CustomExchangeSpecification {
161+ Name : e .exchangeName ,
162+ IsAutoDelete : e .autoDelete ,
163+ ExchangeTypeName : string (e .exchangeType ),
164+ Arguments : e .arguments ,
165+ }
166+ }
167+ }
168+
169+ type bindingRecoveryRecord struct {
170+ sourceExchange string
171+ destination string
172+ isDestinationQueue bool
173+ bindingKey string
174+ arguments map [string ]any
175+ path string
176+ }
177+
178+ func (b * bindingRecoveryRecord ) toIBindingSpecification () IBindingSpecification {
179+ if b .isDestinationQueue {
180+ return & ExchangeToQueueBindingSpecification {
181+ SourceExchange : b .sourceExchange ,
182+ DestinationQueue : b .destination ,
183+ BindingKey : b .bindingKey ,
184+ Arguments : b .arguments ,
185+ }
186+ }
187+ return & ExchangeToExchangeBindingSpecification {
188+ SourceExchange : b .sourceExchange ,
189+ DestinationExchange : b .destination ,
190+ BindingKey : b .bindingKey ,
191+ Arguments : b .arguments ,
192+ }
193+ }
194+
195+ type topologyRecoveryRecords struct {
196+ queues []queueRecoveryRecord
197+ exchanges []exchangeRecoveryRecord
198+ bindings []bindingRecoveryRecord
199+ }
200+
201+ func newTopologyRecoveryRecords () * topologyRecoveryRecords {
202+ return & topologyRecoveryRecords {
203+ queues : make ([]queueRecoveryRecord , 0 ),
204+ exchanges : make ([]exchangeRecoveryRecord , 0 ),
205+ bindings : make ([]bindingRecoveryRecord , 0 ),
206+ }
207+ }
208+
209+ func (t * topologyRecoveryRecords ) addQueueRecord (record queueRecoveryRecord ) {
210+ t .queues = append (t .queues , record )
211+ }
212+
213+ func (t * topologyRecoveryRecords ) removeQueueRecord (record queueRecoveryRecord ) {
214+ t .queues = slices .DeleteFunc (t .queues , func (r queueRecoveryRecord ) bool {
215+ return r .queueName == record .queueName
216+ })
217+ }
218+
219+ func (t * topologyRecoveryRecords ) addExchangeRecord (record exchangeRecoveryRecord ) {
220+ t .exchanges = append (t .exchanges , record )
221+ }
222+
223+ func (t * topologyRecoveryRecords ) removeExchangeRecord (record exchangeRecoveryRecord ) {
224+ t .exchanges = slices .DeleteFunc (t .exchanges , func (r exchangeRecoveryRecord ) bool {
225+ return r .exchangeName == record .exchangeName
226+ })
227+ }
228+
229+ func (t * topologyRecoveryRecords ) addBindingRecord (record bindingRecoveryRecord ) {
230+ t .bindings = append (t .bindings , record )
231+ }
232+
233+ func (t * topologyRecoveryRecords ) removeBindingRecord (bindingPath string ) {
234+ t .bindings = slices .DeleteFunc (t .bindings , func (r bindingRecoveryRecord ) bool {
235+ return r .path == bindingPath
236+ })
237+ }
238+
239+ func (t * topologyRecoveryRecords ) removeBindingRecordBySourceExchange (sourceExchange string ) {
240+ t .bindings = slices .DeleteFunc (t .bindings , func (r bindingRecoveryRecord ) bool {
241+ return r .sourceExchange == sourceExchange
242+ })
243+ }
244+
245+ func (t * topologyRecoveryRecords ) removeBindingRecordByDestinationQueue (destinationQueue string ) {
246+ t .bindings = slices .DeleteFunc (t .bindings , func (r bindingRecoveryRecord ) bool {
247+ return r .destination == destinationQueue
248+ })
249+ }
0 commit comments