EventSource
interface can listen for server-sent events delivered from Pipedream. You can run a Node.js script or a Ruby on Rails app that receives server-sent events, for example.
$.send.sse()
function.
$.send.sse()
.
Send a test event to your workflow, then review the section on Receiving events to see how you can setup an EventSource
to retrieve events sent to the SSE Destination.
Destination delivery is asynchronous. If you iterate over an array of values and send an SSE for each:
await
the execution of the SSE Destination requests in your workflow. We’ll collect every $.send.sse()
call and defer those requests, sending them after your workflow finishes.
$.send.sse
in component actions$.send.sse
.
$.send.sse
functions the same as $.send.sse
in workflow code steps:
EventSource
that connects to the Pipedream SSE stream.
p_aBcDeF
in this URL is the pipeline ID:
p_
prefix is part of the workflow ID.
Once you have the workflow ID, you can construct the event source URL for your SSE destination. That URL is of the following format:
console.log()
all events from an event stream. You can find a lot more examples of how to work with SSE on the web, but this should help you understand the basic concepts.
You’ll need to create two files in the same directory on your machine: an index.html
file for the HTML.
index.html
index.html
page in your browser. In your browser’s developer tools JavaScript console, you should see new events appear as you send them.
Note that the addEventListener
code will listen specifically for events sent to the events channel
specified in our SSE destination. You can listen for multiple types of events at once by adding multiple event listeners on the client.
Try triggering more test events from your workflow while this page is open to see how this works end-to-end.
:keepalive
messagesLegacy proxy servers are known to, in certain cases, drop HTTP connections after a short timeout. To protect against such proxy servers, authors can include a comment line (one starting with a ’:’ character) every 15 seconds or so.Roughly every 15 seconds, we’ll send a message with the
:keepalive
comment to keep open SSE connections alive. These comments should be ignored when you’re listening for messages using the EventSource
interface.