1
0
mirror of synced 2024-11-05 02:59:16 +00:00

[skip appveyor] #9 Documentation and examples

Added Tapeti.Transient documentation.
This commit is contained in:
Mark van Renswoude 2019-08-16 13:45:31 +02:00
parent 7389b5bf06
commit 82646d1b1f
3 changed files with 50 additions and 6 deletions

View File

@ -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`_ 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 Exchanges
--------- ---------

3
docs/rundev.bat Normal file
View File

@ -0,0 +1,3 @@
@Echo Off
start "" "http://localhost:8000/"
sphinx-autobuild . .\_build\html -N

View File

@ -1,11 +1,51 @@
Transient requests Transient requests
================== ==================
The Tapeti.Transient extension provides an RPC mechanism for request - responses.
.. error:: You've stumbled upon a piece of unfinished documentation. While the author does not recommend this pattern for services, opting instead for a self-hosted REST API and a discovery mechanism like `Consul <https://www.consul.io/>`_ 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.
Behind you is all prior knowledge. In front of you is nothing but emptyness. What do you do?
1. Attempt to explore further After enabling Tapeti.Transient you can use ``ITransientPublisher`` to send a request and await it's response, without needing a message controller.
2. Complain to the author and demand your money back
3. Abandon all hope
> | 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<SendCardRequestMessage, SendCardResponseMessage>(
new SendCardRequestMessage
{
RabbitID = rabbit.RabbitID,
Age = rabbit.Age,
Style = CardStyles.Funny
});
// Handle the response
}
}