I am trying to implement Push notifications on Android, using Mosquitto broker.
So, different android application create topics based on tehir id on which they will receive notifications.
To send notifications to those android applications we need the name of the topic.
I am wondering if there is a way to notifiy an application whenever a new topic is created (a new android app is registered). This way, we will have a list of all the topics (so all the androi apps) and we can cpntact them by publishing on their topics.
thanks
A topics is only "created" when something is published to it the first time.
There is no mechanism to detect this apart from subscribing to a wildcard topic that would match all topics of interest and triggering processing when the first message is received on a given topic.
In the case you mentioned you could use a status topic to show when a device is online (and use the Last Will and Testament feature to set offline status) and a separate (but derived) topic for messaging.
Related
I am developing an Android application in Kotlin that can be thought of as similar to Instagram.
I am designing how to implement my in-app notifications. By "in-app notifications" I mean interactions such as likes, publication sharing, new chat message, etc.
For the moment, I do want foreground notifications. The notifications would not involve any view component.
The proposed flow would be:
Interaction action from Client_1 (like, share, message) triggers an Event_A in the server.
Event_A produces a state change and generates a notification to Client_2.
Client_2 receives the notification
a. Display a badge in the notification icon bar.
b. Generates a new item in the notifications list when Client_2 open it.
I make this clarification because, while searching this, I've seen "in-app notifications" are related to campaigns, publicity, new features, etc.
So far, I though two possible implementations but not sure if they are the right ones.
1 - Web Sockets
My app already uses Web Sockets for handling chat messages. However, so far, the connection is only open when the user enters to the chat view.
I consider easy to implement but this implies having an open connection the entire time the user is on the app and may be an unnecessary load for the server and an increment on Web Socket's time session.
2 - SNS + FCM
I've found that AWS SNS and FCM (Firebase Cloud Messaging) is a common approach for handling notifications.
However, reading the Firebase's documentation and examples, I understand it's mostly used for the other kind of in-apps notifications (campaigns, publicity, new features, etc).
In this FCM's documentation, it defines two types of messages: Notification Messages and Data Messages. I understand, Data Messages would be more appropiate for my use case.
Don't know it is worth the complexity of configuring FCM and handling the token's lifecycle.
So, my questions are:
Are the above scenarios good approaches? Is there any other way to achieve this?
Which is the correct term for this kind of notifications?
FCM is just normal push messaging. It can be used for any type of data. It's just a general method for a server to push data to an app, even if the app isn't running at the moment. So it's the right answer. The problem with web sockets is it won't work if your app is shut down either by the user or by the system.
I am working on an app, which requires Android push notifications to be implemented.
I have decided to use Firebase Cloud Messaging directly; without using any other abstraction such as AWS SNS or Pusher.
I would like to avoid storing and managing device tokens in the backend, by using the following approach.
In the android app.
When the user logs into the android application, obtain device token but not send it to the server.
Subscribe to a topic that is based on a agreed convention, such that the topic is unique to that user.
On logout unsubscribe from the topic.
In the Server.
Whenever a situation arises to send a notification to particular user, send push notification to the topic, that is based on the convention.
I would like to know if this is a viable strategy to avoid managing device tokens ?
Case against using topics.
From the official docs.
Based on the publish/subscribe model, FCM topic messaging allows you to send a message to multiple devices that have opted in to a particular topic. You compose topic messages as needed, and FCM handles routing and delivering the message reliably to the right devices.
For example, users of a local weather forecasting app could opt in to a "severe weather alerts" topic and receive notifications of storms threatening specified areas. Users of a sports app could subscribe to automatic updates in live game scores for their favorite teams.
I see that topics are recommended, when multiple devices are to be notified. But I have decided to create a topic per user, this would mean most topics would end up getting subscribed by only one device; Is this approach ok ?
I see that topics are recommended, when multiple devices are to be notified
Yes, multiple devices that have something common to listen to, which is the topic. Topics are used for messages that could be received by the general clients since it is public -- i.e. anyone could subscribe and receive messages sent to it.
What is advised to use for multiple devices, but for the same user is to use Device Groups (see my answer here for tips on Managing Device Groups). However, if you don't mind the "topics being public" part, then your approach should be fine.
Yes, Here required device tokens if we want to send push notification whoever installed your app.
My research we can save device tokens in back end at first time installation of your app that is better according to my understanding so that we can easy to send push notification across all devices.
I read the documentation for FCM in Firebase website, looked into answers here for related questions and googled. All good, but as a newbie I am not sure what's best approach when it comes in choosing the XMPP server.
Is there anything that would limit one of the servers in the list blow when it comes to connecting to FCM? I have a list of servers here.
Should I choose one of the servers in this list for FCM if I need device to device notifications or is there any other choice. I need it for when a new message arrives in a chat app or similar cases when a ChildAdded or modified and the app is backgrounded or closed?
I cannot find any info on the XMPP servers and if Firebase has any recommendation. I would need all three iOS, Android, and Web app support.
I'm currently working on an application build on AWS. At first, the application was on Parse server and the push notifications were not a problem but then, when I migrated to AWS I encountered some issues with that.
As far as I read from this link http://aws.amazon.com/articles/9156883257507082 I learned that I need to create a topic to subscribe users by creating endpoints using the device tokens from where they are currently logged in.
I will have many users, and the notifications will be sent to all endpoints from a topic.
The problem is when I want to send a notification I want to exclude some users from a topic for receiving that, for example, when a user posts something I will not send a notification to him too. This is available also when I have a custom audience to send notifications to. I could create a topic for every event notification to be sent but I don't think this is a efficient method.
Is there a possibility to do that or Amazon does not even support this feature? Until now I didn't find anything on internet that can help me solve this problem and I hope I'll find here someone who worked with this.
Thank you for your time!
Plus : I also found a similar question here Send Push Notifications using Amazon SNS service but I still don't have a certain answer or some links about that.
From what I've found in AWS documentation, it states that
Send messages directly to a specific device by calling the Publish function with the device’s ARN. You can easily scale this to handle millions of users by storing the endpoint ARNs in Amazon DynamoDB and using multi-threaded code on the server.
Thus, to be able to filter users that receive notifications and not send bulk messages to all users subscribed to a topic, you need to send messages using the device's ARNs.
You can find more info here
I am new to gcm api for android and have for some time now i have being working on an android app to allow chatting between two users of the app. The app is such that a chat can only be initiated when one user opts to contact the other user. But my confusion comes in the manner i would be able to create a chatroom for these two users and for the other user to be able receive messages. since i found out that each user must subscribe to a topic inorder to receive messages in that topic. Would i have to subscribe all users to all possible topics or what? that is my big question but it seems it would have so much overhead considering i have 1000+ users.
Please i need all the help i can get here. Thanks
Would i have to subscribe all users to all possible topics or what?
GCM topic messaging allows your app server to send a message to multiple devices that have opted in to a particular topic.
It is not a requirement but it can ease the work for the server to send messages. In this tutorial, you will see that they have created a chat like environment using GCM without using the topic function.
BUT consider the effects on your server like how will it behave on the potential load when you use the topic messaging, especially the the message will trigger an interaction from the user to the server.