akkadotnet/Alpakka

.net Core Support for Azure Service Bus

jblackburn21 opened this issue · 7 comments

Has anyone worked on a port to .net core? If not, I can put a PR together. However, one issue is that the message GetBody() no longer exists on the Message, so a direction would need to be decided.

@jblackburn21 feel free to send a PR. Regarding GetBody() - what's its current replacement?

@Horusiath it just uses a byte array for the body, and leaves the serialization up to the user. I'm using JSON, but it's probably best to leave it up to the user

For example, sending requires this:
new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(messageBody)))

and receiving requires this:

var body = Encoding.UTF8.GetString(msg.Body);
var result = JsonConvert.DeserializeObject<T>(body);

On another note, I wasn't able to get ServiceBusSource fully working due to my lack of understanding of Graphs. The new SDK requires message handlers to be registered with the clients instead of polling. Therefore, I have switched the Logic from TimerGraphStageLogic to GraphStageLogic. I can see that the messages are making it into OnMessage, but they are not getting forwarded to the out source. Can you provide guidance?

private sealed class Logic : GraphStageLogic//  TimerGraphStageLogic
{
  private readonly ServiceBusSource<T> _source;
  private readonly Decider _decider;
  
  public Logic(ServiceBusSource<T> source, Attributes attributes) :  base(source.Shape)
  {
    _source = source;
    _decider = attributes.GetDeciderOrDefault();
  
    SetHandler(source.Out, () =>
    {
      source._client.RegisterMessageHandler(OnMessage);
    });                
  }
  
  private async Task OnMessage(Message message, CancellationToken token)
  {
    var m = _source._extractor(message);
    Emit(_source.Out, m);
    
    await _source._client.CompleteAsync(message.SystemProperties.LockToken);
  }
}

I have figured out how to handle the graph logic by using the lower level MessageSender and MessageReceiver clients. These provide similar APIs to the older version.

@jblackburn21 thanks for figuring that out for yourself. Sorry for not being able to give you any directions. I was not able to respond on time.

@Horusiath No worries, thanks for helping to maintain these libraries. I'm close to having a PR ready, but have one change that I'm unsure about.

Online line 46 of this gist, I need to make an async call inside of OnMessagesReceived, but I think there should be a better way of handling it. Can you review?

https://gist.github.com/jblackburn21/c0aa337e0231759ec3ac686e6280d755

Akka way of working with this kind of behavior is to create a GetAsyncCallback and call it upon task completion. This is not beautiful an probably needs some more user-friendly API. I'll leave the comments in your gist example.

The Akka.Stream.Azure.ServiceBus is now compiled as a .NET Standard 2.0 package, and it should be compatible with the latest .NET Core.