How to configure MassTransit Saga to use several custom named topics? - masstransit

I have a Saga that receives a command from the queue, sends a command to another queue, transitions to another state and waits for an event from the topic the name of which is custom (not named by MassTransit as an event type name). I am having a problem that Saga doesn't react to the event from custom named topic.
The Saga does the following:
Receive a command from the queue.
cfg.ReceiveEndpoint("submit-order-queue", configureEndpoint =>
{
configureEndpoint.ConfigureSaga<OrderShipmentState>(context);
configureEndpoint.RequiresSession = true;
});
Send a command to another queue and transition to another state. I am using a custom activity.
Consume an event from a topic. The topic name needs to be specified.
cfg.SubscriptionEndpoint(
"subsctiption1", "custom-name-topic",
configure =>
{
configure.ConfigureSaga<OrderShipmentState>(context);
});
I found a couple of similar questions like this with an answer from Chris Patterson
If you want to use a subscription endpoint for a saga, you would need
to configure the saga on the corresponding topic for each event.
I tried to achieve this with the code above but I haven't figured out how to specify the event in the configuration above. The method below will not work for me as I need to specify the custom topic name:
void SubscriptionEndpoint<T>(string subscriptionName, Action<IServiceBusSubscriptionEndpointConfigurator> configure) where T : class;
In the result, I am able to execute the 1st and 2nd steps, but on the 3rd step I get an event in the ASB subscription but the Saga doesn't react to that event.
Any suggestions what I am doing wrong?

In the configuration above, the receive endpoint will create subscriptions for each event handled by the saga and those subscriptions will forward messages sent to the topic to the submit-order-queue. You don't need to create the subscription endpoints.

Related

How can Spring Webflux wait for a webhook

I have a GraphQL Websocket based application in which I need to wait for customer payment. The subscription handler is supposed to
Send a request to the payment gateway to activate the payment terminal.
Wait for a webhook that gets called after payment for further processing.
I am sorry I am not able to post any code since, after step 1, I am unable to find details on which constructs (like a Mono or PubSub) to use to "wait" in this use-case.
How can I associate the outgoing request with the webhook call?
I can provide any other details needed to make my question clearer.
There is still too little information but let me give you a rough sketch of how it could work.
After a request to the payment gateway has been sent we need to do two things.
Create a stream (e.g. a Mono) to which you can send a signal
Create a mapping between the (device or transaction) ID and the stream. For starting you can use a simple Map that is also accessible (through a service) by the webhook. For production, you may think about a more sophisticated way.
When the webhook receives a request you look up the stream for the ID and send a signal to it (could also be an error signal). Whoever has subscribed to the stream now receives that signal and can continue.
Now to what construct to use. There may be several alternatives, one is to use a Sink. Here is some pseudo-code(!):
In the method that sends the payment request:
activateTerminal(paymentDetails);
transactionSink = Sinks.empty();
transactionMap.put(deviceId, transactionSink);
return transactionSink.asMono();
Inside the webhook:
transactionSink = transactionMap.get(deviceId);
transactionSink.tryEmitEmpty();
The last statement completes the Mono, so whoever "waits" for it gets notified.
Please understand this answer only as a concept. The things you need to take a closer look at are:
How to store the association
The most appropriate way for you to send a signal to a stream (Mono).
If you have any specific question after that I recommend to create a new one.

Where to subscribe for Redis Pub/Sub in Laravel?

I've been using Redis's Pub/Sub a bit in my application and so far it has been great. I am able to send out a Publish out of Laravel to a different backend process that is able to Subscribe, and eventually Publish an event back to Laravel.
The use case for the user looks like:
submit a form -> wait for a response (a few minutes) -> proceed with transaction
On the backend:
the form posts to a route, then to a controller that publishes this to a subscribed 3rd party (channel one), and eventually that 3rd party publishes back (channel two)
Main Issue: I don't know where the appropriate place to be for subscribing to the (channel two) and processing what gets published there.
Ideally, I'd be able to process Publish requests in two ways:
Letting the user know that their form has been processed and they can move onto the next step (probably with an update to a property a Vue component)
Storing information from the publish into my database.
In the docs, they have it in a Command, which if I try to use here would look like so:
public function handle()
{
Redis::subscribe('channel-two', function ($message) {
// update the client so that the user moves on
// send $message contents to the database
});
}
but that doesn't really seem ideal for me since I want this channel subscribed to 24/7, always listening. Even if it is in a Command, it is still apparent how I would best update the client.
Where in my Laravel project should I be subscribing at? Is there a best practice to respond to these events?
Redis::subscribe is used in a command like in that example for listening on a given channel continuously.
From the docs:
First, let's setup a channel listener using the subscribe method. We'll place this method call within an Artisan command since calling the subscribe method begins a long-running process:
You'll want to run the command using a process manager like supervisor or pm2, much the same as the docs describe running queue listeners.

How to subscribe to a notification stream for packet_In processing?

I am writing an external application that uses REST to communicate with open-daylight. I need to get a notification whenever a new communication between two nodes is needed.
I've checked how to subscribe for event notification in the following link. But I am not sure if this is possible for a packet_in event.
Is it possible to get a notification of the new connection packet_in, with/without some information about the packet?
What would be the path used to create-data-change-event-subscription? also, how can I check all available events and paths that I can make use of?
I believe the "packet_in" event is a yang notification however the REST notification subscription mechanism is for data change notifications. Unfortunately there is no mechanism currently (that I know of) to subscribe to yang notifications over rest.

Freeswitch Originate and session heartbeat

I would like to know how to set the per call heartbeat events to be able to capture the event because I have subscribed to the event SESSION_HEARTBEAT. So far I just subscribed to that event but I cannot capture the event when I made a call.
Please assit.
Google is your friend: https://www.mail-archive.com/freeswitch-users#lists.freeswitch.org/msg17769.html
enable_heartbeat application exists in the source code, but is somehow missing in the Wiki.

How to dynamically create a new a Topic using Events Push plugin

To create a topic for an event I need to declare this in my conf/MyEvents.groovy file as follows:
events = {
"topicName" browser: true
}
I am wanting to use the server push for two things, pushing chat messages to a client and also for pushing notifications to a client.
Using the former as an example, I will need to create a new Topic for each conversation that is instantiated in the chat system at runtime, so that messages can be pushed to each of the conversation participants, so along the lines of
new Event(topic:'anotherTopicName',...)
which will allow me to call from a service :
import grails.events.*
class MyService {
def doSomething(){
...
event(topic:'anotherNewTopic', data:data)
}
}
Is there a method that will allow me to create a new Event topic? Or is there another way to implement this using Events Push
I've just done something similar. I needed to show some notifications based on the user that had logged in, so I set this in MyEvents.groovy:
events = {
'newNotification_*' browser:true
}
And when I need to send the notification:
event topic:"newNotification_${userId}",data:n
Then in my browser I can listen to those notifications with something similar to this:
grailsEvents.on("newNotification_"+myUser,function(data){

Resources