# Event Streams API Preview

**URL:** <https://forum.inductiveautomation.com/t/event-streams-api-preview/98796>\
**Category:** Module Development\
**Created:** [November 19, 2024, 5:38pm UTC](https://forum.inductiveautomation.com/t/event-streams-api-preview/98796 "2024-11-19T17:38:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cody.tamaki](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@cody.tamaki](https://forum.inductiveautomation.com/u/cody.tamaki)\
**Post date:** [November 19, 2024, 5:38pm UTC](https://forum.inductiveautomation.com/t/event-streams-api-preview/98796/1 "2024-11-19T17:38:29Z")

</div>

Could somebody point me towards the classes we'd be using in 8.3 to publish events for the new event streams feature coming? I'm working on a feature right now that would probably utilize this in the future so I'd like to plan ahead if possible 🙂

---

<div class="post-metadata">

**Author:** ![jimender2](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@jimender2](https://forum.inductiveautomation.com/u/jimender2)\
**Post date:** [December 2, 2024, 5:51am UTC](https://forum.inductiveautomation.com/t/event-streams-api-preview/98796/2 "2024-12-02T05:51:23Z")

</div>

You can look around in here though I dont see anything yet about it.

> **[Overview](https://files.inductiveautomation.com/sdk/javadoc/earlyaccess/ignition83/8.3.0-SNAPSHOT/index.html)**
>
> package index

---

<div class="post-metadata">

**Author:** ![cody.tamaki](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@cody.tamaki](https://forum.inductiveautomation.com/u/cody.tamaki)\
**Post date:** [December 4, 2024, 5:18pm UTC](https://forum.inductiveautomation.com/t/event-streams-api-preview/98796/3 "2024-12-04T17:18:48Z")

</div>

Yeah I guess since there isn't anything here, is there any way of knowing what the API will look like from Inductive to publish a new event? I'm assuming we'll just need a namespace/topic and a payload?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 4, 2024, 6:11pm UTC](https://forum.inductiveautomation.com/t/event-streams-api-preview/98796/4 "2024-12-04T18:11:58Z")

</div>

It's not showing up because the event streams feature hasn't been merged in yet. It's going to be a new module, so once you've marked it as a dependency and pulled it in you'll be able to compile against it.

On the gateway, you'll have to register your source and/or handler with a central registry, which will call a startup method on your hook that delivers you an `EventStreamSource.Subscriber` that you submit events to whenever your code deems it appropriate:

```java
/**
 * Provides {@link EventPayload} to the Event Stream through the {@link Subscriber} interface.
 */
public interface EventStreamSource {

    /**
     * Registered with {@link EventStreamRegistry} to create concrete implementation of
     * {@link EventStreamSource} from the provided configuration.
     */
    @FunctionalInterface
    interface Factory {

        /**
         * Called once when Event Stream is first created.
         * @param context {@link EventStreamContext}
         * @param config {@link EventStreamSource} configuration that defines its behavior
         * @return {@link EventStreamSource}
         */
        EventStreamSource create(EventStreamContext context, JsonObject config);

    }

    /**
     * Interface for submitting events to the Event Stream.
     */
    interface Subscriber {

        /**
         * Notifies Event Stream that events have arrived and are ready to process.
         * <br>
         * This call will never block. If blocking is desired, use the returned {@link CompletionStage} to wait for
         * the event to be processed.
         *
         * @param events List of events to pass Event Stream to start processing.
         *
         * @return Future of results that completes once all {@code events} have been processed.
         */
        CompletionStage<EventResultList> submitEvents(List<EventPayload> events);

        /**
         * Notifies Event Stream that an event has arrived and are ready to process. If multiple events are available,
         * {@link Subscriber#submitEvents} should be used.
         * <br>
         * This call will never block. If blocking is desired, use the returned {@link CompletionStage} to wait for
         * the event to be processed.
         *
         * @param event Event to pass Event Stream to start processing.
         *
         * @return Future of results that completes once all {@code events} have been processed.
         */
        default CompletionStage<EventResult> submitEvent(EventPayload event) {
            return submitEvents(List.of(event)).thenApply(results -> results.results().get(0));
        }

        /**
         * Notifies Event Stream an error occurred. This is primarily used for diagnostics, the Event Stream will still
         * be considered running until Shutdown. If the error is resolved events can continue to be submitted
         *
         * @param throwable Throwable that caused the error.
         */
        void onError(Throwable throwable);
    }

    /**
     * Called on Event Stream startup. Events can safely be sent to {@link Subscriber#submitEvents} or
     * {@link Subscriber#submitEvent}.
     */
    void onStartup(Subscriber subscriber);

    /**
     * Called on {@link EventStreamSource} shutdown. No more events should be sent through {@link Subscriber}. If
     * events are submitted after, they'll immediately complete with Error result.
     */
    void onShutdown();
}

```

You'll separately have to register different configuration (mostly for the sake of UI) in the designer to have a way to actually configure whatever settings make sense for your source, much like the way Perspective handles binding configuration.

Disclaimer: This code isn't merged yet and obviously we're pre-public-beta here, so this API is potentially subject to change still.

---

<div class="post-metadata">

**Author:** ![cody.tamaki](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@cody.tamaki](https://forum.inductiveautomation.com/u/cody.tamaki)\
**Post date:** [December 4, 2024, 7:09pm UTC](https://forum.inductiveautomation.com/t/event-streams-api-preview/98796/5 "2024-12-04T19:09:27Z")

</div>

Thank you Paul! What's in an EventPayload if you don't mind me asking?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 4, 2024, 10:53pm UTC](https://forum.inductiveautomation.com/t/event-streams-api-preview/98796/6 "2024-12-04T22:53:42Z")

</div>

`EventPayload` is just a wrapper class that contains an arbitrary Object and optional 'metadata' in the form of a `Map<String, Object>`. Pretty maximally flexible.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 12, 2024, 11:54pm UTC](https://forum.inductiveautomation.com/t/event-streams-api-preview/98796/7 "2024-12-12T23:54:19Z")

</div>

Event streams has been merged and the Javadoc updated accordingly:

> **[com.inductiveautomation.eventstream](https://files.inductiveautomation.com/sdk/javadoc/earlyaccess/ignition83/8.3.0-SNAPSHOT/com/inductiveautomation/eventstream/package-summary.html)**
>
> declaration: package: com.inductiveautomation.eventstream

---

<div class="post-metadata">

**Author:** ![jimender2](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@jimender2](https://forum.inductiveautomation.com/u/jimender2)\
**Post date:** [December 16, 2024, 11:29am UTC](https://forum.inductiveautomation.com/t/event-streams-api-preview/98796/8 "2024-12-16T11:29:27Z")

</div>

Looks awesome. I cant wait to get my hands on it. The module we are building is north of 200k loc and I can see Event streams helping simplify bits and pieces of it.
