I have a SignalR application that uses RabbitMq for message processing in the background. (.Net Core 2.1) The process is like this:
- Client connects to SignalR hub
- Client pushes a message to SignalR hub.
- SignalR Hub publishes the message to RabbitMq Queue.
- This is critical (I don't know this part)- Something is subscribed to RabbitMq queue
- When the message comes to the queue, something notifies clients by using the SignalR hub.
Now the problem I have is in the step 4. That something, I don't know where to put it.
First I tough to put it into SignalR hub, so SignalR hub would subscribe to RabbitMq queue and handle the messages. But SignalR hubs are short-lived and recreated on each request, so when the RabbitMq message is dequeued, the SignalR hub context is already disposed.
Then I tough to create a singleton service at application start and do the subscription to RabbitMq queues there, but at application start I don't know who are the clients that need's to subscribe to the RabbitMq queue. Requirements are that a subscription is made for each consumer client that connects to the SignalR hub.
Because I use "topic" exchange where the topic and clientId is know only when the consumer client is connected, i need to subscribe to RabbitMq when the consumer client connects to SignalR hub ie. (OnConnected method on SignalR hub)
I need help on this, how to do the subscription to RabbitMq queue on SignalR client connected, and this needs to be long lived.and cliendId