Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 6. APNS

Apns Component

Available as of Camel 2.8
The apns component is used for sending notifications to iOS devices. The apns components use javapns library. The component supports sending notifications to Apple Push Notification Servers (APNS) and consuming feedback from the servers.
The consumer is configured with a default polling time of 3600 seconds. It is advisable to consume the feedback stream from Apple Push Notification Servers regularly at larger intervals to avoid flooding the servers.
The feedback stream gives information about inactive devices. This information can be consumed infrequently (every two or three hours) if your mobile application is not heavily used.
To configure an apns component to use Transport Layer Security (TLS), see chapter "Configuring Transport Security for Camel Components" in "Security Guide".
Maven users will need to add the following dependency to their pom.xml for this component:
    <!-- use the same version as your Camel core version -->

URI format

To send notifications:
To consume feedback:



Property Default Description
tokens Empty by default. Configure this property in case you want to statically declare tokens related to devices you want to notify. Tokens are separated by comma.


Property Default Description
delay 3600 Delay in seconds between each poll.
initialDelay 10 Seconds before polling starts.
timeUnit SECONDS Time Unit for polling.
userFixedDelay true If true, use fixed delay between pools, otherwise fixed rate is used. See ScheduledExecutorService in JDK for details.
You can append query options to the URI in the following format, ?option=value&option=value&...


The ApnsComponent must be configured with a com.notnoop.apns.ApnsService. The service can be created and configured using the org.apache.camel.component.apns.factory.ApnsServiceFactory. See further below for an example. For further information, see the test source code.

Exchange data format

When Camel fetches feedback data corresponding to inactive devices, it retrieves a List of InactiveDevice objects. Each InactiveDevice object on the retrieved list will be set as the In body, and then processed by the consumer endpoint.

Message Headers

Camel Apns uses these headers.
Property Default Description
CamelApnsTokens Empty by default.
CamelApnsMessageType STRING, PAYLOAD, APNS_NOTIFICATION If you choose PAYLOAD as the message type, the message will be considered an APNS payload and sent as is. If you choose STRING, the message will be converted to an APNS payload. APNS_NOTIFICATION is used for sending message body as com.notnoop.apns.ApnsNotification types.

ApnsServiceFactory Builder Callback

ApnsServiceFactory comes with an empty callback method that can be used to configure or replace the default ApnsServiceBuilder instance. The method has the following format:
protected ApnsServiceBuilder configureServiceBuilder(ApnsServiceBuilder serviceBuilder);
It is used in the following way:
ApnsServiceFactory proxiedApnsServiceFactory = new ApnsServiceFactory(){

  protected ApnsServiceBuilder configureServiceBuilder(ApnsServiceBuilder serviceBuilder) {
    return serviceBuilder.withSocksProxy("", 6666);



Camel Xml route

<beans xmlns=""

	<!-- Replace by desired values -->
	<bean id="apnsServiceFactory" class="org.apache.camel.component.apns.factory.ApnsServiceFactory">

		<!-- Optional configuration of feedback host and port -->
		<!-- <property name="feedbackHost" value="localhost" /> -->
		<!-- <property name="feedbackPort" value="7843" /> -->

		<!-- Optional configuration of gateway host and port -->
		<!-- <property name="gatewayHost" value="localhost" /> -->
		<!-- <property name="gatewayPort" value="7654" /> -->

		<!-- Declaration of certificate used -->
                <!-- from Camel 2.11 onwards you can use prefix: classpath:, file: to refer to load the certificate from classpath or file. Default it classpath -->
		<property name="certificatePath" value="certificate.p12" />
		<property name="certificatePassword" value="MyCertPassword" />

		<!-- Optional connection strategy - By Default: No need to configure -->
		<!-- Possible options: NON_BLOCKING, QUEUE, POOL or Nothing -->
		<!-- <property name="connectionStrategy" value="POOL" /> -->
		<!-- Optional pool size -->
		<!-- <property name="poolSize" value="15" /> -->

		<!-- Optional connection strategy - By Default: No need to configure -->
		<!-- Possible options: EVERY_HALF_HOUR, EVERY_NOTIFICATION or Nothing (Corresponds to NEVER javapns option) -->
		<!-- <property name="reconnectionPolicy" value="EVERY_HALF_HOUR" /> -->

	<bean id="apnsService" factory-bean="apnsServiceFactory" factory-method="getApnsService" />

	<!-- Replace this declaration by wanted configuration -->
	<bean id="apns" class="org.apache.camel.component.apns.ApnsComponent">
		<property name="apnsService" ref="apnsService" />

	<camelContext id="camel-apns-test" xmlns="">
        	<route id="apns-test">
                	<from uri="apns:consumer?initialDelay=10&elay=3600&imeUnit=SECONDS" />
        	        <to uri="log:org.apache.camel.component.apns?showAll=true&ultiline=true" />
                	<to uri="mock:result" />


Camel Java route

Create camel context and declare apns component programmatically

    protected CamelContext createCamelContext() throws Exception {
        CamelContext camelContext = super.createCamelContext();

        ApnsServiceFactory apnsServiceFactory = new ApnsServiceFactory();

        ApnsService apnsService = apnsServiceFactory.getApnsService(camelContext);

        ApnsComponent apnsComponent = new ApnsComponent(apnsService);
        camelContext.addComponent("apns", apnsComponent);

        return camelContext;

ApnsProducer - iOS target device dynamically configured via header: "CamelApnsTokens"

    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                    .setHeader(ApnsConstants.HEADER_TOKENS, constant(IOS_DEVICE_TOKEN))

ApnsProducer - iOS target device statically configured via uri

    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                to("apns:notify?tokens=" + IOS_DEVICE_TOKEN);



See Also