How to configure endpoint for Saga when multiple consumer - masstransit

I need to configure endpoint on Saga 'Consumer' such as "queue:send-notification" to move from Publish to Send, because I have redundancy on my service (and right now) each email is sent twice.
How can I do that for both test:
x.UsingInMemory((context, cfg) =>
{
cfg.UseInMemoryScheduler(out ISchedulerFactory factory);
_scheduler = factory.GetScheduler();
cfg.UseInMemoryOutbox();
cfg.ConfigureEndpoints(context);
});
And
x.UsingRabbitMq((context, cfg) =>
{
cfg.ConfigureEndpoints(context);
...
cfg.UseMessageScheduler(schedulerEndpoint);
cfg.UseMessageRetry(r => r.Intervals(config.GetSection(RetryIntervalsKey).Get<int[]>()));
cfg.UseInMemoryOutbox();
});
Does the addition of
EndpointConvention.Map<SendNotification>(new Uri("queue:send-notification"));
Is enough??

Well, first, if you have a "redundancy" where you are using the same message type for two separate things, you should resolve that issue. Or if you have two consumers that are sending email notifications in response to the same event, fix that problem.
The use of EndpointConvention is NEVER recommended.
You can, however, use .SendAsync() from the saga, and pass the destination address as the first parameter so that the message is sent instead of using .PublishAsync().
Though it seems like you have system design/architecture issues given the use of the same contract in multiple email delivery services.

Related

Sending Private Message ( Socket.IO )

In many Posts or Articles.I often saw something like that.
Client-Side :
socket.emit("shhh!Secrets", {
To : "AlexId",
Message : "Hello World!"
})
Server-Side:
socket.on("shhh!Secrets", (Send) => {
io.in(Send.TO).emit("SO...Secrets", Send.Message)
})
Whatever it is socketId , Specific user socketObj or room base .
What If I change Client Source code and change with others room or socketId then my crazy message will saved to others chat timeline...
First Method
Socket.IO is stateful. So this Smart Socket will not forget who you are in every event call.
lets say user want to join room001
So when Joining a socket to a specific Room,Save RoomId To socket.roomId = "room001"
Then use io.in(socket.roomId).emit("SO...Secrets", "message")
Second Method
Never give a change a client directly send message to specific room.
Server-Side:
socket.on("shhh!Secrets", (Send) => {
// Send message only if the user already joined to this Room
if (Send instanceof Object && socket.rooms[Send.TO] === Send.TO)
io.in(Send.TO).emit("SO...Secrets", Send.Message);
})
Mohammed, of course you can change your client code, but you need to know real userId (AlexId in your example), and it is usually uuid, that is not easy to get... So there is very low chance to do that.
By the way, usually in articles use very simple examples and do not mention security aspects, so be careful with it!

How to fix the user info doesn't shows up on the page

I am following the Presence Channels section in Laravel docs.
1.Authorizing Presence Channels-I created I function to check is user is authorized to access them.
Broadcast::channel('chat', function ($user) {
...
return user_info;
})
2.Joining Presence Channels-They say I must use Echo's join method. So I did.
Echo.join('chat')
.here((users) => {
console.log('hello',users)
this.users = users;
})
.joining((user) => {
console.log('hey you', user)
this.users.push(user);
})
.leaving((user) => {
this.users.splice(this.users.indexOf(user), 1);
})
Here's the part that confuses me. "The data returned by the authorization callback will be made available to the presence channel event listeners in your JavaScript application". I assume that I suppose to have this Javascript. part and it should be an event listener. I just can't understand where should it be and how I must call it. Have it something to do with a function I use when user logged in?
So, help me understand how to implement these 'presence channel event listeners in your JavaScript application.'
"The data returned by the authorization callback will be made available to the presence channel event listeners in your JavaScript application."
https://laravel.com/docs/5.8/broadcasting#authorizing-presence-channels
This means that the data returned by your authorization callback Broadcast::channel(...) which is $user_info will be available to the joining() and leaving() listeners, or any custom listeners, within your JavaScript application.
The currently defined listeners are waiting to hear another user join or leave the chat channel. Therefore, each user must also fire the corresponding events within their own instance of the application.
// join the channel — trigger joining()
Echo.join('chat');
// leave the channel — trigger leaving()
Echo.leave('chat');

Live Queries subscription updates in Parse-server

Is it possible to get subscription alerts for live queries on a single client instead of everyone. I am using the following code to get update alerts for the object 'obj' on class 'class-name'. But the alert message comes on every client( i.e every instance of running app).
let query_add = new Parse.Query("class-name");
let subscription = query_add.subscribe();
subscription.on('update', (obj) => {
alert('object updated');
});
How can I modify this to notify only the single client.

Parse Cloud Code to send push notification to group of other users

I have an app where one user can invite other users to join an event by push notification. Let's say when creating an event, the user add other users to this event, then save the event to Parse.
So basically I have an array of user_id and I will call a function from cloud code to push notification to those Id, after saving the event.
1)Will the following Cloud code work?
Parse.Cloud.afterSave( "Event", function(request) {
//Get value from Ticket Object
var ids = request.object.get("inviteeIds");
//Set push query
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.containedIn("objectId",ids);
//Send Push message
Parse.Push.send({
where: pushQuery,
data: {
alert: "New Event Added",
sound: "default"
}
},{
success: function(){
response.success('true');
},
error: function (error) {
response.error(error);
}
});
});
I am not sure if the containedIn function exist or not:
pushQuery.containedIn("objectId",ids);
When I search I only find documentation about equalTo function, e.g:
query.equalTo('injuryReports', true);
2) I also read about Channel, but I still not understand how to apply it in my situation. From the documentation:
Devices start by subscribing to one or more channels, and
notifications can later be sent to these subscribers.
In my case how can I create a Channel and then add ids of friends who I want to invite to this Channel?
If possible, I would like to use Cloud Code rather than pushing from mobile device.
1)Will the following Cloud code work?
Why don't you try it and see for yourself, then come back with the errors, if any? Anyway, there's no response in afterSave. It will return a success regardless of what happens in it.
Otherwise it may work. Try running it.
I am not sure if the containedIn function exist or not:
Parse.Query.containedIn
2) I also read about Channel, but I still not understand how to apply it in my situation
Basically you subscribe to a particular channel in the client. Like this (Android)
ParsePush.subscribeInBackground("channelName");
Then in the Cloud
Parse.Push.send({
channels: channelList,
data: {
// etc
}
});
Obviously you'll need to know the channels you want to target.
You can subscribe multiple users to the same channel (for example you can have a dedicated channel for a particular event) or you can have one channel per user (for example you can name it something like channel_<userId> and only subscribe that user to it). Up to you what you need or what you want.
One last thing...
So basically I have an array of user_id
Keep in mind that objects stored in the database have a limited size. If your object gets too big and has too much data, you won't be able to add any more to it.

Laravel 4.1 + Push Queues + Error Queues

My goal is to somehow notify me if a push message fails after X attempts.
Iron.io push queues docs describe: Error Queues
http://dev.iron.io/mq/reference/push_queues/#error_queues
Following the docs, I have to define an error_queue option in order to failed messages trigger a message in the specified error_queue option.
How can I define an option if push method in IronQueue.php doesn't support option argument. I see that pushRaw does support option argument.
How can I transform the following push example into a pushRaw
Route::get('someroute', function()
{
Queue::push('SomeClass', array('time' => time()));
});
class SomeClass{
public function fire($job, $data)
{
// do something
$job->delete();
}
}
Other ways of detecting push queues fails are also welcome.
As #cmancre said, you can use HUD to set the error queue or you could use the API to set it: http://dev.iron.io/mq/reference/api/#update_a_message_queue
Iron guys just rolled out an UI allowing us to set a error_error via iron admin panel.
In case your error_queue is already firing, to complete the cycle, you need to know which message failed.
To grab the error message information, in the error_queue route just do:
// First we fetch the Request instance
$request = Request::instance();
// Now we can get the content from it
$content = $request->getContent();
Reference: http://www.codingswag.com/2013/07/get-raw-post-data-in-laravel/

Resources