nestjs icon indicating copy to clipboard operation
nestjs copied to clipboard

How publish a message?

Open bolognesi opened this issue 6 years ago • 3 comments

Hello, thanks for this library! I was wondering how it is possible write (i.e. publish) on the message bus. Using the pubSubHandler I can receive the messages, but it is not clear to me how to write messages on an exchange.

Thanks, best wishes Thomas

bolognesi avatar Jan 22 '20 15:01 bolognesi

Hey @bolognesi thanks for your interest in the library. This part of the docs needs to be improved but sending messages is quite simple. Assuming you've included the RabbitMQModule in your application, you can simply inject the AmqpConnection into the controller/service from which you would like to publish messages and interact with the connection directly.

Here's an example from the integration tests of publishing a message:

https://github.com/golevelup/nestjs/blob/7b1a665fa7678575fda40dd9ca85ef6d0dd4d580/integration/rabbitmq/e2e/subscribe.e2e-spec.ts#L58

I'll try and make some much needed improvements to the docs in the coming week. Feel free to re-open if this doesn't get you up and running but I'm going to close this issue for now

WonderPanda avatar Jan 22 '20 16:01 WonderPanda

@bolognesi

I've added a Table of Contents and new sections to the RabbitMQ docs to explain this better

https://github.com/golevelup/nestjs/tree/master/packages/rabbitmq#sending-messages

WonderPanda avatar Jan 28 '20 13:01 WonderPanda

@WonderPanda Great job and great library.Thanks!

bolognesi avatar Jan 28 '20 14:01 bolognesi