@@ -9,10 +9,11 @@ type AMQPBindingInfo struct {
99}
1010
1111type AMQPBinding struct {
12- sourceExchange IExchangeSpecification
13- destinationQueue IQueueSpecification
14- bindingKey string
15- management * AmqpManagement
12+ sourceName string
13+ destinationName string
14+ toQueue bool
15+ bindingKey string
16+ management * AmqpManagement
1617}
1718
1819func newAMQPBinding (management * AmqpManagement ) * AMQPBinding {
@@ -25,28 +26,54 @@ func (b *AMQPBinding) Key(bindingKey string) IBindingSpecification {
2526}
2627
2728func (b * AMQPBinding ) SourceExchange (exchangeSpec IExchangeSpecification ) IBindingSpecification {
28- b .sourceExchange = exchangeSpec
29+ b .sourceName = exchangeSpec .GetName ()
30+ b .toQueue = false
31+ return b
32+ }
33+
34+ func (b * AMQPBinding ) SourceExchangeName (exchangeName string ) IBindingSpecification {
35+ b .sourceName = exchangeName
36+ b .toQueue = false
37+ return b
38+ }
39+
40+ func (b * AMQPBinding ) DestinationExchange (exchangeSpec IExchangeInfo ) IBindingSpecification {
41+ b .destinationName = exchangeSpec .GetName ()
42+ b .toQueue = false
43+ return b
44+ }
45+
46+ func (b * AMQPBinding ) DestinationExchangeName (exchangeName string ) IBindingSpecification {
47+ b .destinationName = exchangeName
48+ b .toQueue = false
2949 return b
3050}
3151
3252func (b * AMQPBinding ) DestinationQueue (queueSpec IQueueSpecification ) IBindingSpecification {
33- b .destinationQueue = queueSpec
53+ b .destinationName = queueSpec .GetName ()
54+ b .toQueue = true
55+ return b
56+ }
57+
58+ func (b * AMQPBinding ) DestinationQueueName (queueName string ) IBindingSpecification {
59+ b .destinationName = queueName
60+ b .toQueue = true
3461 return b
3562}
3663
3764func (b * AMQPBinding ) Bind (ctx context.Context ) error {
3865 path := bindingPath ()
3966 kv := make (map [string ]any )
4067 kv ["binding_key" ] = b .bindingKey
41- kv ["source" ] = b .sourceExchange . GetName ()
42- kv ["destination_queue" ] = b .destinationQueue . GetName ()
68+ kv ["source" ] = b .sourceName
69+ kv ["destination_queue" ] = b .destinationName
4370 kv ["arguments" ] = make (map [string ]any )
4471 _ , err := b .management .Request (ctx , kv , path , commandPost , []int {responseCode204 })
4572 return err
4673}
4774
4875func (b * AMQPBinding ) Unbind (ctx context.Context ) error {
49- bindingPathWithExchangeQueueKey := bindingPathWithExchangeQueueKey (b .sourceExchange , b .destinationQueue , b .bindingKey )
76+ bindingPathWithExchangeQueueKey := bindingPathWithExchangeQueueKey (b .toQueue , b .sourceName , b . destinationName , b .bindingKey )
5077 _ , err := b .management .Request (ctx , amqp.Null {}, bindingPathWithExchangeQueueKey , commandDelete , []int {responseCode204 })
5178 return err
5279}
0 commit comments