I'm using adapter for Service Bus Queue. Therefore, I shouldn't use any class of Queue for return type. But I'm stucked on ReceiveAsync()
method. How can I map Task<BrokeredMessage> to Task<MyAdapterClass>
?
Here is adapter Class for BrokeredMessage
public class QueueMessage : IQueueMessage
{
private BrokeredMessage _message;
public T Body<T>()
{
T result = default(T);
if (_message != null)
result = _message.GetBody<T>();
return result;
}
public BrokeredMessage Message { set { _message = value; } }
public string Label
{
get
{
var result = "";
if (_message != null)
result = _message.Label;
return result;
}
}
public void MoveToDeadLetter()
{
if (_message != null)
_message.DeadLetter();
}
public void Complete()
{
if (_message != null)
_message.Complete();
}
public async void CompleteAsync()
{
if (_message != null)
await _message.CompleteAsync();
}
public async void AbandonAsync()
{
if (_message != null)
await _message.AbandonAsync();
}
public void Abandon()
{
if (_message != null)
_message.Abandon();
}
public string MessageId
{
get
{
return _message == null ? null : _message.MessageId;
}
set { if (_message != null) _message.MessageId = value; }
}
public string CorrelationId
{
get
{
return _message == null ? null : _message.CorrelationId;
}
set { if (_message != null) _message.CorrelationId = value; }
}
public int DeliveryCount { get { return _message == null ? -1 : _message.DeliveryCount; } }
}
And I want Method like this
public Task<IQueueMessage> ReceiveAsync(TimeSpan serverWaitTime)
{
Task<QueueMessage> task= QueueClient.ReceiveAsync(serverWaitTime);
return task;
}
On Driver project I want to use task like this:
var task1 = _queueAdapter.ReceiveAsync(new TimeSpan(200)).ContinueWith(ReadMessageAsync);