diff --git a/docs/indepth.rst b/docs/indepth.rst index 25d6821..131f273 100644 --- a/docs/indepth.rst +++ b/docs/indepth.rst @@ -135,6 +135,7 @@ The routing key is determined by converting CamelCase to dot-separated lowercase This behaviour is implemented using the IRoutingKeyStrategy interface. For more information about changing this, see `Overriding default behaviour`_ +.. note:: As you can see the namespace in which the message class is declared is not used in the routing key. This means you should not use the same class name twice as it may result in conflicts. The exchange strategy described below helps in differentiating between the messages, but to avoid any confusion it is still best practice to use unambiguous message class names or use another routing key strategy. Exchanges --------- diff --git a/docs/rundev.bat b/docs/rundev.bat new file mode 100644 index 0000000..1410909 --- /dev/null +++ b/docs/rundev.bat @@ -0,0 +1,3 @@ +@Echo Off +start "" "http://localhost:8000/" +sphinx-autobuild . .\_build\html -N \ No newline at end of file diff --git a/docs/transient.rst b/docs/transient.rst index efe2cbb..c17652e 100644 --- a/docs/transient.rst +++ b/docs/transient.rst @@ -1,11 +1,51 @@ Transient requests ================== +The Tapeti.Transient extension provides an RPC mechanism for request - responses. -.. error:: You've stumbled upon a piece of unfinished documentation. - Behind you is all prior knowledge. In front of you is nothing but emptyness. What do you do? +While the author does not recommend this pattern for services, opting instead for a self-hosted REST API and a discovery mechanism like `Consul `_ if an immediate response is required and a queue is not (like when providing an API for a frontend application), it can still be useful in certain situations to use the Tapeti request - response mechanism and be able to wait for the response. - 1. Attempt to explore further - 2. Complain to the author and demand your money back - 3. Abandon all hope +After enabling Tapeti.Transient you can use ``ITransientPublisher`` to send a request and await it's response, without needing a message controller. - > | +Enabling transient requests +--------------------------- +To enable the transient extension, include it in your TapetiConfig. You must provide a timeout after which the call to RequestResponse will throw an exception if no response has been received (for example, when the service handling the requests is not running). + +Optionally you can also provide a prefix for the dynamic queue registered to receive responses, so you can distinguish the queue for your application in the RabbitMQ management interface. If not provided it defaults to "transient". + + +:: + + var config = new TapetiConfig(new SimpleInjectorDependencyResolver(container)) + .WithTransient(TimeSpan.FromSeconds(30), "myapplication.transient") + .RegisterAllControllers() + .Build(); + + +Using transient requests +------------------------ +To send a transient request, inject ITransientPublisher into the class where you want to use it and call RequestResponse: + +:: + + public class BirthdayHandler + { + private ITransientPublisher transientPublisher; + + public BirthdayHandler(ITransientPublisher transientPublisher) + { + this.transientPublisher = transientPublisher; + } + + public async Task SendBirthdayCard(RabbitInfo rabbit) + { + var response = await transientPublisher.RequestResponse( + new SendCardRequestMessage + { + RabbitID = rabbit.RabbitID, + Age = rabbit.Age, + Style = CardStyles.Funny + }); + + // Handle the response + } + }