Skip to content

Instantly share code, notes, and snippets.

@matzew
Created April 25, 2018 09:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matzew/f18d481da8fbd61a9ebca90cec46b192 to your computer and use it in GitHub Desktop.
Save matzew/f18d481da8fbd61a9ebca90cec46b192 to your computer and use it in GitHub Desktop.

HTTP Rest API receive 'push request', this gets processed in PushNotificationSenderEndpoint.send(), which eventually calls an async EJB (NotificationRouter.submit()) which performs a grouping/mapping and fires a CDI event per Variant.

This Event is received in the MessageHolderWithVariantsProducer.queueMessageVariantForProcessing() method, which basically sticks the submitted event into a transactional JMS send, based on the variant type a different queue is selected (mainly to keep things separated). The JMS listener MessageHolderWithVariantsConsumer.onMessage() reads from these queues, and fires a different CDI event, which kicks in the TokenLoader.

The TokenLoader generally iterates over all variants (for a given type, see the grouping/mapping done in NotificationRouter), and starts to query tokens from the database, as a steam.

The tokens are in different batches, with different default sizes per Push_Network, to not overflow the push network (e.g. google (non topic case) only allows 1k, per http invocation), as well the load/memory in the server. Once the number of tokens is reached, the tryToDispatchTokens() fires a different CDI event, which is consumed by the MessageHolderWithTokensProducer.queueMessageVariantForProcessing(). The methods sends the payload to a JMS queue, that represents the actual push network (mainly to keeps separated). There is a listener (MessageHolderWithTokensConsumer.onMessage()), that reads from the queues, firing an event, that it did dequeue a container objects with a number of tokens, for a given push network. There is an EJB that does receive this event (`NotificationDispatcher.sendMessagesToPushNetwork()), and it does select (using CDI selectors) the actual instance of the desired PushNotification sender and hands the payload to it. The different implementations deal with the specifics of the PushNetworks.

  • PushyApnsSender for APNs/iOS, based on the pushy library, which leverages Netty for HTTP/2-Network IO.
  • FCMPushNotificationSender for FCM/Android. It's using an older Google library that performs vanilla HttpURLConnection calls to the given Endpoint for FCM
  • WNSPushNotificationSender talks HTTP to Microsoft using the java-wns library. NOTE: usually not really much use this stuff.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment