Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/carlosCharz/fcmxmppserverv2
XMPP Connection Server for FCM using the latest version of the Smack library (4.3.4) + Connection Draining Implementation
https://github.com/carlosCharz/fcmxmppserverv2
fcm firebase-cloud-messaging java smack smack-library upgrade xmpp xmpp-connection
Last synced: 21 days ago
JSON representation
XMPP Connection Server for FCM using the latest version of the Smack library (4.3.4) + Connection Draining Implementation
- Host: GitHub
- URL: https://github.com/carlosCharz/fcmxmppserverv2
- Owner: carlosCharz
- Created: 2016-10-21T20:04:33.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-12-05T22:19:07.000Z (11 months ago)
- Last Synced: 2024-07-30T21:06:32.000Z (4 months ago)
- Topics: fcm, firebase-cloud-messaging, java, smack, smack-library, upgrade, xmpp, xmpp-connection
- Language: Java
- Homepage:
- Size: 120 KB
- Stars: 47
- Watchers: 10
- Forks: 33
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-2.0.txt
Awesome Lists containing this project
README
# XMPP Connection Server for FCM (Upgrade from Smack 3.x to 4.x) + Connection Draining Implementation
This is an upgrade of my last [FCM XMPP Connection Server](https://github.com/carlosCharz/fcmxmppserver) application. Now, this project uses the latest version at this time of the Smack library (4.3.4). _**I just added the connection draining implementation to this project. If you had some problems check my troubleshooting section!**_The new version has introduced new terminology, deprecated some older methods and enriched the library in general. The problem started when there is a no working example out there using the new version to build a XMPP CCS for FCM. In summary, the API changes from the 3.x to the 4.x version are:
1. XMPPConnection is now an interface. Use either AbstractXMPPConnection or one of its subclasses (XMPPTCPConnection).
2. XMPPConnection.addPacketListener is deprecated: use either addAsyncPacketListener or addSyncPacketListener.
3. Packet became a deprecated interface. Use the new Stanza class.
4. The Packet Extension term is now Extension Element.
5. Some methods of ConnectionListener that belongs to the reconnection were moved to ReconnectionListener.
For more information you must read the following documentation:
* [The upgrade guide](https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide)
* [New Smack Terminology](https://github.com/igniterealtime/Smack/wiki/New-Smack-Terminology)
* [The Smack Javadoc](http://download.igniterealtime.org/smack/docs/latest/javadoc/)_**ADDITIONAL USEFUL LINKS**_
* [XMPP Connection Server for FCM](https://github.com/carlosCharz/fcmxmppserver): This project is the original code base and it gives you a simple explanation of FCM XMPP Connection Server.
* [FCM Connection Draining solution explanation](https://youtu.be/6AQCnNWPksg): This video explains how I handle the FCM Connection Draining message.## New Smack libraries
* [Smack java 7](https://mvnrepository.com/artifact/org.igniterealtime.smack/smack-java7)
* [Smack tcp](https://mvnrepository.com/artifact/org.igniterealtime.smack/smack-tcp)
* [Smack extensions](https://mvnrepository.com/artifact/org.igniterealtime.smack/smack-extensions)## How to start the server
Just because it is the same project as my prior solution, the way to start the server is exactly the same. You can read my [how to start the server](https://github.com/carlosCharz/fcmxmppserver).## Troubleshooting
This is a simple java code. You can integrate with just spring or spring in a container (Tomcat for example). In any case you need to take into account these issues:1. _**If using a simple java application, keep the application alive listening messages.**_ This problem occurs when you use a simple java code as a daemon in linux (that's why I put the while true workaround).
2. _**If using a java server (with spring boot at least), close the XMPP connection when the server goes down.**_ This problem occurs when even if you shutdown the server the XMPP connection is still open and handling incoming messages. I do not know yet if this is a spring boot problem. The thing is like we are wrapping the XMPP CCS Server into a HTTP interface just to treat it as a normal server. My workaround was putting the disconnection in the spring preDestroy. @PreDestroy public void springPreDestroy() { //ccsConnection.disconnect(); }
3. _**Reconnection when connection draining.**_ The reconnection should be handled to connect again to the FCM using the same parameters with a backoff strategy. Smack can handle the automatic reconnection if you enable it but if the connection will be closed from the FCM side you should call your reconnection method when FCM sends connection draining control message or connection draining error message.
4. _**Handle properly the new connection creation.**_ If you handle differently the connection draining or use the reconnect. Always make sure that when you create a new connection the old one is completely closed gracefully to avoid phantom connections!
## About me
I am Carlos Becerra - MSc. Softwware & Systems. You can contact me via:* [Google+](https://plus.google.com/+CarlosBecerraRodr%C3%ADguez)
* [Twitter](https://twitter.com/CarlosBecerraRo)## Thanks
To tell the truth. I was really worried looking for the right solution. Finally, I made a list of useful links (apart from the above documentation links).* [gcm server](http://www.marothiatechs.com/2015/08/building-your-own-android-chat_18.html)
* [stanza](http://www.programcreek.com/java-api-examples/index.php?api=org.jivesoftware.smack.packet.Stanza)
* [a problem](https://community.igniterealtime.org/thread/59532)
* [other gcm server](https://github.com/googlesamples/friendlyping/blob/master/server/Java/src/main/java/com/gcm/samples/friendlyping/GcmServer.java)_**Any improvement or comment about the project is always welcome! As well as others shared their code publicly I want to share mine! Thanks!**_
## License
```javas
Copyright 2020 Carlos BecerraLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.