Guarding against missed messages in AppEngine Channel API - google-app-engine

In the AppEngine Channel API, channels automatically close after 2 hours. We are handling this by rejoining the channel in the onError event.
Is there a chance the messages could get missed if they are sent while the channel is reconnecting?
Our scenario: We have an appointment scheduling system where appointments are booked elsewhere through an API. We use the channel to display new appointments on the schedule as they arrive. But I'm concerned that some appointments could get missed if they are booked during the time when a channel is closed and reconnected. Does the Channel API guard against this?

A little bit of background: the "client id" in the Channel API is used to create a transient XMPP endpoint. A given client id will always map to the same transient endpoint. So when you re-connect using a token to a channel created with the same client id, you are reconnecting to the same endpoint. Because of this you might see behavior where your client gets messages sent before recreating the channel. But there are no guarantees and we don't actively queue messages when they're sent to a channel with no listening clients.
In your case, could you return an up-to-date list of appointments as part of the same response that returns a new token?

You're not 'reconnecting' the channel, you're creating an entirely new one - so yes, messages could be missed. You should get an exception if you try to send a message to a closed channel, however.

Related

Discord.py real-time response to messages after going offline?

My Google-fu has failed me, Stack Overflow Gods...
I have a very basic bot running on 4 of my servers that handles scheduling and, as long as the bot is online, it works marvelously, but as soon as it goes offline for whatever reason, it stops listening to any of the messages already in the channel and will only listen to newly sent messages.
E.G. Let's say that every time the bot is online is starts a new session and when it goes offline, that session ends. So, if my bot is online for the first time, it's in Session 1 and listens to all messages sent during Session 1, but as soon as it goes offline, Session 1 ends. When it comes back online, it starts Session 2 and stops listening to messages that were sent during Session 1 and only listens to messages that are sent during Session 2.
How can I get the bot to listen to all the messages in one channel? (How can I get it to listen to all messages from all "Sessions")
Thank you kindly

Fiware cepheus cep subscription to context broker issue

I wanted to make the cepheus cep receive incoming events from the context broker rather than the cepheus broker but then I checked the cepheus-cep logs when I uploaded the config.json file and found that it doesn't subscribe to the entities in the context broker as there's no subscription launched. Also when I tried send the subscription manually on behalf of the cepheus-cep and started to send messages to the entities in the context broker, the Cepheus-cep treated the notifications as mere post request not as eventin messages that should be processed and it displays a message stating "POST method not supported".
So, what could be the solution for both issues regarding the Cep subscription to context broker and the manual subscription I made?

Pushing data across App Engine instances

Let's say we have several clients connected to App Engine using Channel API. Each client sends messages, which should be propagated to other conntected clients according to some rules. The tricky part is that clients may not be to the same App Engine instance.
Is there any way to push data from one instance to the others?
(Yes, I know about Memcache, but this would require some kind of polling.)
You're asking two questions here.
a. Can you push data from one instance to another without the use of polling. The answer is generally no.
b. Can one client send messages to the server that can be propagated to other clients? Yes, and this does not require propagating messages to other server-side instances.
Consider the Channel API as a service. Clients are connected to the Channel API service; they are not connected to any particular instance. Therefore any instance can send messages to any client.
You'll need to store the Channel tokens of your clients in the datastore, in some way that's queryable to match your rules.
Your client makes an HTTP request to send a message to your server.
The handler on the server queries for channel tokens that it needs to propagate the message to (either from memcache or datastore).
The handler on the server sends messages to all the clients.
If the list of destination clients is extremely large, you might want to do steps 3/4 in a task queue where the operation can run longer.
It does not matter what instance a client is connected to, that's hidden from you by the API.
Clients can only "reply" to message via standard HTTP commands, they don't actually have any way to respond via the channel API directly.
So Client A on server A1 wants to sent a message to client B on server B1.
Client A posts to a handler. That might be instance A1 or B1. It does not matter which as the server now passes the message on to client B whatever server client B is connected to via the Channel API.
The real point is that no App Engine instance has any data at all, in general. So it does not matter which instance you connect to, it might be the 99th instance or the very first to start up. So you have to design your application so that it's irrelevant what instance is in use.
Client sends message to server via HTTP.
Server sends message to N clients via the channel API.
Channel API does not make a fixed frontend-instance-to-client connection. Any frontend instance can push message to channel if it knows the channel ID.
What you need to do is pass messages cross-channel.
User one sends message normally to server (e.g. via GET)
Server looks up channel ID of second user and pushes the message
Repeat procedure in other direction: second user to first user.

Google Channel API sends a message to all clients

I created a working Google Channel AP and now I would like to send a message to all clients.
I have two servlets. The first creates the channel and tells the clients the userid and token. The second one is called by an http post and should send the message.
To send a message to a client, I use:
channelService.sendMessage(new ChannelMessage(channelUserId, "This is a server message!"));
This sends the message just to one client. How could I send this to all?
Have I to store every Id which I use to create a channel and send the message for every id? How could I pass the Ids to the second servlet?
Using Channel API it is not possible to create one channel and then having many subscribers to it. The server creates a unique channel for individual JavaScript clients, so if you have the same Client ID the messages will be received only by one.
If you want to send the same message to multiple clients, in short, you will have to keep a track of active clients and send the same message to all of them.
If that approach sounds scary and messy, consider using PubNub for your push notification messages, where you can easily create one channel and have many subscribers. To make it run on Google App Engine is not that hard, since they support almost any platform or device.
I know this is an old question, but I just finished an open source project that uses the Channel API to implement a publish/subscribe model, i.e. you can have multiple users subscribe to a single topic, and then all those subscribers will be notified when anyone publishes a message to the topic. It also has some nice features like automatic message persistence if desired, and "return receipts", where a subscriber can be notified whenever OTHER subscribers receive that message. See https://github.com/adevine/gaewebpubsub#gae-web-pubsub. Licensed under Apache 2.0 license.

Google App Engine Channel Token and Client ID relationship

In Google App Engine documentation for Channel API, it is stated that "Only one client at a time can connect to a channel using a given Client ID".
In contradiction, when I try to create a channel with the same Client ID, a new channel is consumed. In other words, when I call creat channel api for ClientID "user_one" channelService.createChannel("user_one"); for ten times, 10 different channels with 10 different token strings would be created, and when I send a message to "user_one" channelService.sendMessage(new ChannelMessage("user_one", message));, all of the ten clients on different devices, would receive the message!
How would you describe this scenario ? How one can benefit from this mechanism (one clientID with different channel, all receiving same message)? how to prevent it from creating multiple channel for single user ?
The documentation is not complete but it describes its intent pretty well. It says:
Only one client at a time can connect to a channel using a given Client ID, so an application cannot use a Client ID for fan-out. In other words, it's not possible to create a central Client ID for connections to multiple clients (For example, you can't create a Client ID for something like a "global-high-scores" channel and use it to broadcast to multiple game clients.)
It's up to you to keep track of the of the number of channels you create for each ClientID. From my experience, what you describe works, but not reliably. The newest channel created with the ClientID works, the older ones, sometimes work, sometimes don't receive messages.
Note that if you're trying this out on the dev_appserver, all the clients receive messages, but on the real server this behavior is not the same.

Resources