Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Introduction

The JAX-RS 2.1 introduced the support of server-sent events (SSE).

...

Code Block
java
java
final JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint(<application>, JAXRSServerFactoryBean.class);
factory.setFeatures(Arrays.asList(new SseFeature()));
...
return factory.create();

Additional Properties

There are a couple of contextual properties which allow to fine-tune the Apache CXF SSE implementation to a particular context.

PropertyDescriptionDefault
org.apache.cxf.sse.sink.buffer.size

By default, the SSE events are scheduled in batches and than flushed one by one.
If the buffer overflows, no more events are going to be accepted (and consequently, the error is returned).
The size of the buffer could be controlled using this property (if default is not suitable).

10000

OSGi

For the deployments inside OSGi containers (like Apache Karaf), Apache CXF provides a dedicated cxf-sse feature (which depends on cxf-http and cxf-jaxrs).

...

Code Block
xml
xml
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:cxf="http://cxf.apache.org/blueprint/core"
       xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"

       xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
                           http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
                           http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd">

    <bean id="sseFeature" class="org.apache.cxf.jaxrs.sse.SseFeature" />

    <cxf:bus>
        <cxf:features>
            <cxf:logging />
        </cxf:features>
    </cxf:bus>

    <jaxrs:server id="sseSampleService" address="/">
        <jaxrs:serviceBeans>
            <ref component-id="..." />
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <ref component-id="..." />
        </jaxrs:providers>
        <jaxrs:features>
            <ref component-id="sseFeature" />
        </jaxrs:features>
 </jaxrs:server>
</blueprint>

...

Before 3.2.5 release

Although SSE in general works on top of HTTP transport, the SSE implementation in CXF uses the dedicated one, based on Atmosphere framework. This transport only required on the server-side (client side works over normal HTTP) and is fully compatible with HTTP transport.

...