@@ -38,6 +38,7 @@ private enum PauseStatus
3838 private readonly Guid _id = Guid . NewGuid ( ) ;
3939
4040 private ReceiverLink ? _receiverLink ;
41+ private Attach ? _attach ;
4142
4243 private PauseStatus _pauseStatus = PauseStatus . UNPAUSED ;
4344 private readonly UnsettledMessageCounter _unsettledMessageCounter = new ( ) ;
@@ -57,8 +58,8 @@ public override async Task OpenAsync()
5758 {
5859 try
5960 {
60- TaskCompletionSource < ReceiverLink > attachCompletedTcs =
61- Utils . CreateTaskCompletionSource < ReceiverLink > ( ) ;
61+ TaskCompletionSource < ( ReceiverLink , Attach ) > attachCompletedTcs =
62+ Utils . CreateTaskCompletionSource < ( ReceiverLink , Attach ) > ( ) ;
6263
6364 // this is an event to get the filters to the listener context
6465 // it _must_ be here because in case of reconnect the original filters could be not valid anymore
@@ -72,14 +73,24 @@ public override async Task OpenAsync()
7273 _configuration . ListenerContext ( listenerContext ) ;
7374 }
7475
75- Attach attach = Utils . CreateAttach ( _configuration . Address , DeliveryMode . AtLeastOnce , _id ,
76- _configuration . Filters ) ;
76+ Attach attach ;
77+
78+ if ( _configuration . DirectReplyTo )
79+ {
80+ attach = Utils . CreateDirectReplyToAttach ( _id , _configuration . Filters ) ;
81+ }
82+ else
83+ {
84+ string address = AddressBuilderHelper . AddressBuilder ( ) . Queue ( _configuration . Queue ) . Address ( ) ;
85+ attach = Utils . CreateAttach ( address , DeliveryMode . AtLeastOnce , _id ,
86+ _configuration . Filters ) ;
87+ }
7788
7889 void OnAttached ( ILink argLink , Attach argAttach )
7990 {
8091 if ( argLink is ReceiverLink link )
8192 {
82- attachCompletedTcs . SetResult ( link ) ;
93+ attachCompletedTcs . SetResult ( ( link , argAttach ) ) ;
8394 }
8495 else
8596 {
@@ -103,10 +114,10 @@ void OnAttached(ILink argLink, Attach argAttach)
103114 // which tells me it allows the .NET runtime to process
104115 await Task . Delay ( ConsumerDefaults . AttachDelayMilliseconds ) . ConfigureAwait ( false ) ;
105116
106- _receiverLink = await attachCompletedTcs . Task . WaitAsync ( waitSpan )
117+ ( _receiverLink , _attach ) = await attachCompletedTcs . Task . WaitAsync ( waitSpan )
107118 . ConfigureAwait ( false ) ;
108119
109- if ( false == Object . ReferenceEquals ( _receiverLink , tmpReceiverLink ) )
120+ if ( ! ReferenceEquals ( _receiverLink , tmpReceiverLink ) )
110121 {
111122 // TODO log this case?
112123 }
@@ -136,7 +147,7 @@ private void ValidateReceiverLink()
136147
137148 if ( _receiverLink . LinkState != LinkState . Attached )
138149 {
139- var errorMessage = _receiverLink . Error ? . ToString ( ) ?? "Unknown error" ;
150+ string errorMessage = _receiverLink . Error ? . ToString ( ) ?? "Unknown error" ;
140151 throw new ConsumerException ( $ "{ ToString ( ) } Receiver link not attached. Error: { errorMessage } ") ;
141152 }
142153 }
@@ -245,6 +256,15 @@ ref Unsafe.As<PauseStatus, int>(ref _pauseStatus),
245256 /// </summary>
246257 public long UnsettledMessageCount => _unsettledMessageCounter . Get ( ) ;
247258
259+ public string ? QueueAddress
260+ {
261+ get
262+ {
263+ string ? x = _attach ? . Source is not Source source ? null : source . Address ;
264+ return x ;
265+ }
266+ }
267+
248268 /// <summary>
249269 /// Request to receive messages again.
250270 /// </summary>
@@ -298,7 +318,8 @@ await _receiverLink.CloseAsync(TimeSpan.FromSeconds(5))
298318
299319 public override string ToString ( )
300320 {
301- return $ "Consumer{{Address='{ _configuration . Address } ', " +
321+ string address = AddressBuilderHelper . AddressBuilder ( ) . Queue ( _configuration . Queue ) . Address ( ) ;
322+ return $ "Consumer{{Address='{ address } ', " +
302323 $ "id={ _id } , " +
303324 $ "Connection='{ _amqpConnection } ', " +
304325 $ "State='{ State } '}}";
0 commit comments