streadway / amqp

Go client for AMQP 0.9.1
http://godoc.org/github.com/streadway/amqp
BSD 2-Clause "Simplified" License
4.88k stars 621 forks source link

How to use AMQP for websockets Pub/Sub using GoRoutine and channels #417

Closed KabDeveloper closed 5 years ago

KabDeveloper commented 5 years ago

HI,

How to use AMQP in order to create one instance (Go Routine) that listen for my webserver to receive data, manipulate them and then Publish messages using websocket to users's browser.

I am not looking for all the code but for this particulary:

And this worker must be launched one time only and working in concurrency with my main program.

I checked this example: https://github.com/streadway/amqp/blob/master/_examples/pubsub/pubsub.go

But I can't see how it is possible to send message using channels to the producer ? and this can be done anytime and from any part of my code.

I mean a way to pass directly channel message to Publish GoRoutine function (This function must be working in LOOP in concurrency with my program so I can pass messages and then publish them to users).

Your guidance will be welcomed, thanks in advance.

michaelklishin commented 5 years ago

This sounds more like a question about using WebSockets in Go than anything specific to this client. Also, note that RabbitMQ supports STOMP over WebSockets and MQTT over WebSockets which I'd consider. STOMP and MQTT clients can interoperate with AMQP 0-9-1 clients that use this library, although with some reasonable limitations.

KabDeveloper commented 5 years ago

@michaelklishin Hi and thanks for your answer.

But my question is not related to your answer, I am not looking for client browser integration but a way to pass websocket message in the server side using channels to the worker responsible to produce them throue websockets and send them to the client browser.

I am not looking for the browser side, but only sending message using channel from the main program to the worker for better performances. It is specific for this client, sorry if I didn't exposed in the right way my concern.

michaelklishin commented 5 years ago

I'm not sure what the question really is. You can consume from a Go channel and publish on an amqp channel. This library does not impose a lot of limitations on how that can be done. Concurrent publishing on a shared amqp channel is not supported in the protocol, so you have to batch and synchronise. That's pretty much the only limitation. Publisher side data safety is another concern that makes this a less-than-trivial problem.