Watermark usage in push notification of EWS(java) - java

Could anyone please elaborate a bit on watermark and its use with respect to recreating subscription using push notification in EWS application?
I read the Microsoft provided information regarding it. But I did not get to understand accurately its usage.
It is explained as:
"The Watermark element represents an event bookmark in the mailbox event queue."
Does it mean that for every event we get new or different watermark in the notification?
Also:
"If a Subscribe request contains a watermark, the subscription is created from the watermark forward."
Does it mean that if we subscribe using a watermark previously sent to us, we can get or identify all the events occurred after it?

Does it mean that for every event we get new or different watermark in the notification?
Yes as the Events are delivered to you client you will get the Water-Mark associated for that event in the Queue.
Does it mean that if we subscribe using a watermark previously sent to us, we can get or identify all the events occurred after it?
Yes if you use a previous watermark your client is telling the server to send the events that occurred after that watermark. Watermarks are valid for 30 days but there are events that can trigger them to become invalid eg
https://blogs.msdn.microsoft.com/exchangedev/2008/07/24/transitioning-to-exchange-web-services-notifications/ . So you need to consider that if you using them for synchronisation.

Related

Discord Bot Java - I'm trying to have my bot send a message every so often and need help on which event listener is best suited

I want my bot to send a message randomly throughout the day.
I was using the onMessageReceived event to achieve this, but that depends on a user sending a message, and I want the bot to still send a message randomly even if there hasn't been any server activity for a while.
Basically, what I'm hoping to find is if there's an Event Listener that fires every few seconds consistently while the bot is online. The event shouldn't be dependent on if users send messages or if people join voice channels, etc.
Does anyone know of an Event Listener that could help me achieve this?
Just use a timer in your bot after you run a command, you could add a command like !motd random for a random interval and then if you wanted to do it after a certain period of time do !motd 3hours

Java,Spring,Push Notification

I want to implement push notification in java so please help me out
1-Each time a new record(Message) pushed into data base(due to event created by some other user), a push notification should be sent to specific Logged in user automatically.
2-Content of the push notification should be the message present in the db.
3-If there are multiple messages, then the user should receive them one by one in a queue fashion.
4-Most important thing is the logged in user need not have to trigger any event to get notification, user should receive it automatically throughout the session.
You could use Server Sent Events. Java provides SseEmitter to send timely notifications.
You can use EventSource API in JavaScript to trigger the SSE event stream and in the server-side, loop the database query code which is wrapped by an ExecutorService - which can spin of separate thread based on the initialization.
Put SSE timeout to -1 for listening for an infinite amount of time.
Please note this answer is only a hint. Use these to explore more from the internet.

Azure Event Hub Offset

I have implemented the code from the below link for receiving events from the event hub. But say there are 10 events and checkpoint is done for every 5 events. Now the program exits abnormally when reading the 7th event and if i restart the event processor host again then events (1,2,3,4,6) are re-read. Please suggest how will I again avoid re-read and read from the 7th event? Any example would be appreciated. Thanks.
https://github.com/Azure/azure-event-hubs/blob/master/samples/Java/src/main/java/com/microsoft/azure/eventhubs/samples/Basic/EventProcessorSample.java
Well, in the context of the event hub it is your job to handle possible message duplication as the event hub guarantees at least once delivery, see
Does Azure Event Hub guarantees at least once delivery?
We do not know your scenario so we cannot suggest something other than for you to build a duplicate message detection mechanism. For example, adding a unique id to the data prior to sending it to the event hub and have the processor check that against a list of processed messages.

Telegram bot api: Error code 429, Error: Too many requests: retry later

We have a Telegram bot. It has around 1.2 million subscribers.
Now we're facing a problem in sending messages to these number of subscribers.
Telegram bot API does not provide any batch message functionality and we'd have to send individual requests to Telegram. The problem is, after a few thousand messages, Telegram starts responding with Error 429: too many requests, and does not accept any requests for a while.
How can we effectively message our subscribers?
You should simply implement a global rate limiter to ensure no single user gets above a fixed number of messages per second. to be safe, set your limiter at lower than 30, maybe even to 5 msgs per second.
Really anything higher than 5 messages per second to a single user quickly becomes an annoyance.
cheers.
I'm the owner of Ramona Bot.
There is a limit for sending message to users. as they said ~30 message per second. Otherwise you will get that Error 429.
Based on the Telegram Bots FAQ for sending messages, you should consider this:
If you're sending bulk notifications to multiple users, the API will not allow more than 30 messages per second or so. Consider spreading out notifications over large intervals of 8—12 hours for best results.
I had similar problems with messages, the pause between which was 0.5 seconds (this is much less than 30 messages per second!). The problem was only associated with messages, the content of which I tried to change. So when you try to use "edit_message_text" or "edit_message_media" take more pause between messages.
It can happen also if a Telegram group is in the slow mode and the bot tries to send more that one message at once to that group. I fixed this by adding a delay to the bot trigger mechanism.

Resume PullSubscription later for EWS

All code examples I've seen kind of work like this
subscribe to pullsubscription
get back subscriptionID, watermark
now loop through getEvents() until done, updating watermark
possibly unsubscribe.
In short they assume you are doing the pulling in a single thread/process, and
will not need to again pull using the same watermark/subscription ID again.
The API itself doesn't have a "resumePullScription(subscriptionID,watermark). It just
has beginSubscribe(folders,events,watermark). It's unclear to me whether I can
use that watermark again later with another beginSubscribe, since the subscriptionID
cannot be supplied.
I want to subscribe and get a watermark at time T0
At another time T1, within the timeout interval I want to getEvents again. This is a separate thread, so I need to reconnect to existing subscription/watermark.
It seems like I have two choices for time T1
unsubscribe # time T0,and then resubscribe # time T1 with watermark, but wont watermark be lost because of the unsubscribe?
resubscribe passing just the watermark, but will ews be smart enough to hook up to same subscription? or will watermark be ignored? or will subscription budget grow..?
At any rate it's not actually very clear what happens when subscription expires. I would assume watermark would go, but I see info claiming watermark will survive for 30 days. So then, whats the point of subscription id ?
The PullSubscription class in the EWS Manaaged API doesn't have a constructor to allow you to instantiate it by itself (I guess this was a boarder case in their design). So if you want to do this you would need to use either some ProxyCode eg http://msdn.microsoft.com/en-us/library/office/exchangewebservices.geteventstype(v=exchg.150).aspx or use raw soap and a httpclass to issue the GetEvents request and parse the result.
Basically while the Subscription is valid (eg within the timeout period) you should be able to use GetEvents with the SubscriptionId and a valid watermark (the watermark should be good for the 30 days.If you have unsubscribed the event the watermark wouldn't be valid because it would have been removed from the Events Table.
Cheers
Glen

Categories

Resources