zeromq / netmq

A 100% native C# implementation of ZeroMQ for .NET
Other
2.95k stars 744 forks source link

ResponseSocket / RequestSocker .NET Core worker service #957

Open emmett-miller opened 3 years ago

emmett-miller commented 3 years ago

Environment

NetMQ Version:    4.0.1.6
Operating System:  Windows AMD64
.NET Version:     .NET Core 3.1

Expected behaviour

  1. Send a request message from a RequestSocket
  2. A ResponseSocket reads the request message
  3. The ResponseSocket sends the response message
  4. The RequestSocket receives the message from the ResponseSocket

protected override async Task ExecuteAsync(CancellationToken stoppingToken) { using (var server = new ResponseSocket("@tcp://127.0.0.1:5556")) { var result = server.ReceiveFrameString(); // A ResponseSocket reads the request message } }

Actual behaviour

no message was received

Steps to reproduce the behaviour

send message over port 5556 using requestsocket add .net core 3.1 worker service and add code above install worker service as windows service deploy using sc.exe

stefanodelpero commented 3 years ago

I've the same problem with .NET 5.0 Worker Service

abeham commented 3 years ago

I suppose, because ExecuteAsync never hands back the control, the worker service cannot actually continue. What if you wrap that whole code in an await Task.Run(() => { ... })?

Other option is to use Async methods of NetMQ and await the results, but that requires to set up a NetMQRuntime.

stefanodelpero commented 3 years ago

@abeham yes, await Task.Run(() => { ... }) works. Thank you!

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had activity for 365 days. It will be closed if no further activity occurs within 56 days. Thank you for your contributions.