aboutsummaryrefslogtreecommitdiff
path: root/public/simple-server-sent-events-based-pubsub-server.html
diff options
context:
space:
mode:
Diffstat (limited to 'public/simple-server-sent-events-based-pubsub-server.html')
-rwxr-xr-xpublic/simple-server-sent-events-based-pubsub-server.html16
1 files changed, 8 insertions, 8 deletions
diff --git a/public/simple-server-sent-events-based-pubsub-server.html b/public/simple-server-sent-events-based-pubsub-server.html
index ce2e260..a5b1bef 100755
--- a/public/simple-server-sent-events-based-pubsub-server.html
+++ b/public/simple-server-sent-events-based-pubsub-server.html
@@ -22,7 +22,7 @@ Events</a>
22to all the subscribers.</ul><h2 id=how-exactly-does-the-pubsub-model-work>How exactly does the pub/sub model work?</h2><p>The easiest way to explain this is with diagram bellow. Basic function is 22to all the subscribers.</ul><h2 id=how-exactly-does-the-pubsub-model-work>How exactly does the pub/sub model work?</h2><p>The easiest way to explain this is with diagram bellow. Basic function is
23simple. We have subscribers that receive messages, and we have publishers that 23simple. We have subscribers that receive messages, and we have publishers that
24create and post messages. Similar model is also well know pattern that works on 24create and post messages. Similar model is also well know pattern that works on
25a premise of consumers and producers, and they take similar roles.<figure><img src=/posts/simple-pubsub-server/pubsub-overview.png alt="How PubSub works"></figure><p><strong>These are some naive characteristics we want to achieve:</strong><ul><li>producer is publishing messages to subscribe topic,<li>consumer is receiving messages from subscribed topic,<li>servers is also known as Broker,<li>broker does not store messages or tracks success,<li>broker uses 25a premise of consumers and producers, and they take similar roles.<figure><img loading="lazy" src=/posts/simple-pubsub-server/pubsub-overview.png alt="How PubSub works"></figure><p><strong>These are some naive characteristics we want to achieve:</strong><ul><li>producer is publishing messages to subscribe topic,<li>consumer is receiving messages from subscribed topic,<li>servers is also known as Broker,<li>broker does not store messages or tracks success,<li>broker uses
26<a href=https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)>FIFO</a> method 26<a href=https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)>FIFO</a> method
27for delivering messages,<li>if consumer wants to receive messages from a topic, producer and consumer 27for delivering messages,<li>if consumer wants to receive messages from a topic, producer and consumer
28topics must match,<li>consumer can subscribe to multiple topics,<li>producer can publish to multiple topics,<li>each message has a messageId.</ul><p><strong>Known drawbacks:</strong><ul><li>messages will not be stored in a persistent queue or unreceived messages like 28topics must match,<li>consumer can subscribe to multiple topics,<li>producer can publish to multiple topics,<li>each message has a messageId.</ul><p><strong>Known drawbacks:</strong><ul><li>messages will not be stored in a persistent queue or unreceived messages like
@@ -32,7 +32,7 @@ Events</a>
32opens a long-running connection between the client and the server so make sure 32opens a long-running connection between the client and the server so make sure
33if your setup is load balanced that the load balancer in this case can have 33if your setup is load balanced that the load balancer in this case can have
34long opened connection,<li>no system moderation due to the dynamic nature of creating queues.</ul><h2 id=server-sent-events>Server-Sent Events</h2><p>Read more about it on <a href=https://html.spec.whatwg.org/multipage/server-sent-events.html>official specification 34long opened connection,<li>no system moderation due to the dynamic nature of creating queues.</ul><h2 id=server-sent-events>Server-Sent Events</h2><p>Read more about it on <a href=https://html.spec.whatwg.org/multipage/server-sent-events.html>official specification
35page</a>.<h3 id=current-browser-support>Current browser support</h3><figure><img src=/posts/simple-pubsub-server/caniuse.png alt="Browser support"></figure><p>Check 35page</a>.<h3 id=current-browser-support>Current browser support</h3><figure><img loading="lazy" src=/posts/simple-pubsub-server/caniuse.png alt="Browser support"></figure><p>Check
36<a href="https://caniuse.com/#feat=eventsource">https://caniuse.com/#feat=eventsource</a> 36<a href="https://caniuse.com/#feat=eventsource">https://caniuse.com/#feat=eventsource</a>
37for latest information about browser support.<h3 id=known-issues>Known issues</h3><ul><li>Firefox 52 and below do not support EventSource in web/shared workers<li>In Firefox prior to version 36 server-sent events do not reconnect 37for latest information about browser support.<h3 id=known-issues>Known issues</h3><ul><li>Firefox 52 and below do not support EventSource in web/shared workers<li>In Firefox prior to version 36 server-sent events do not reconnect
38automatically in case of a connection interrupt (bug)<li>Reportedly, CORS in EventSource is currently supported in Firefox 10+, Opera 38automatically in case of a connection interrupt (bug)<li>Reportedly, CORS in EventSource is currently supported in Firefox 10+, Opera
@@ -55,7 +55,7 @@ server that triggers browser to threat response as a EventStream.<p>Headers resp
55Events</a> 55Events</a>
56which is quite nice and available from Developer Tools under Network tab.<blockquote><p>You can debug only client side events that get received and not the server 56which is quite nice and available from Developer Tools under Network tab.<blockquote><p>You can debug only client side events that get received and not the server
57ones. For debugging server events add <code>console.log</code> to <code>server.js</code> code and 57ones. For debugging server events add <code>console.log</code> to <code>server.js</code> code and
58print out events.</blockquote><figure><img src=/posts/simple-pubsub-server/chrome-debugging.png alt="Google Chrome Developer Tools EventStream"></figure><h2 id=server-implementation>Server implementation</h2><p>For the sake of this example we will use <a href=https://nodejs.org/en/>Node.js</a> with 58print out events.</blockquote><figure><img loading="lazy" src=/posts/simple-pubsub-server/chrome-debugging.png alt="Google Chrome Developer Tools EventStream"></figure><h2 id=server-implementation>Server implementation</h2><p>For the sake of this example we will use <a href=https://nodejs.org/en/>Node.js</a> with
59<a href=https://expressjs.com>Express</a> as our router since this is the easiest way to 59<a href=https://expressjs.com>Express</a> as our router since this is the easiest way to
60get started and we will use already written SSE library for node 60get started and we will use already written SSE library for node
61<a href=https://www.npmjs.com/package/sse-pubsub>sse-pubsub</a> so we don't reinvent the 61<a href=https://www.npmjs.com/package/sse-pubsub>sse-pubsub</a> so we don't reinvent the
@@ -305,11 +305,11 @@ setting can be adjusted in <code>server.js</code> file; search for the
305</span></span><span style=display:flex><span> &lt;/body&gt; 305</span></span><span style=display:flex><span> &lt;/body&gt;
306</span></span><span style=display:flex><span> 306</span></span><span style=display:flex><span>
307</span></span><span style=display:flex><span>&lt;/html&gt; 307</span></span><span style=display:flex><span>&lt;/html&gt;
308</span></span></code></pre><h2 id=reading-further>Reading further</h2><ul><li><a href=https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events>Using server-sent events</a><li><a href=https://www.smashingmagazine.com/2018/02/sse-websockets-data-flow-http2/>Using SSE Instead Of WebSockets For Unidirectional Data Flow Over HTTP/2</a><li><a href=https://apifriends.com/api-streaming/server-sent-events/>What is Server-Sent Events?</a><li><a href=https://tools.ietf.org/id/draft-xie-bidirectional-messaging-01.html>An HTTP/2 extension for bidirectional messaging communication</a><li><a href=https://developers.google.com/web/fundamentals/performance/http2>Introduction to HTTP/2</a><li><a href=https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API>The WebSocket API (WebSockets)</a></ul></div></article></main><section><hr><h2>Posts from blogs I follow around the net</h2><ul><li><a href=https://utcc.utoronto.ca/~cks/space/blog/solaris/ZFSWhyNotDirectoryToFilesystem target=_blank rel=noopener>One reason that ZFS can't turn a directory into a filesystem</a> — <a href=https://utcc.utoronto.ca/~cks/space/blog/>Chris's Wiki :: blog</a><div>One of the wishes that I and other people frequently have for ZFS 308</span></span></code></pre><h2 id=reading-further>Reading further</h2><ul><li><a href=https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events>Using server-sent events</a><li><a href=https://www.smashingmagazine.com/2018/02/sse-websockets-data-flow-http2/>Using SSE Instead Of WebSockets For Unidirectional Data Flow Over HTTP/2</a><li><a href=https://apifriends.com/api-streaming/server-sent-events/>What is Server-Sent Events?</a><li><a href=https://tools.ietf.org/id/draft-xie-bidirectional-messaging-01.html>An HTTP/2 extension for bidirectional messaging communication</a><li><a href=https://developers.google.com/web/fundamentals/performance/http2>Introduction to HTTP/2</a><li><a href=https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API>The WebSocket API (WebSockets)</a></ul></div></article></main><section><hr><h2>Posts from blogs I follow around the net</h2><ul><li><a href=https://utcc.utoronto.ca/~cks/space/blog/linux/NFSv4ServerLockClients target=_blank rel=noopener>Finding which NFSv4 client owns a lock on a Linux NFS(v4) server</a> — <a href=https://utcc.utoronto.ca/~cks/space/blog/>Chris's Wiki :: blog</a><div>A while back I wrote an entry about finding which NFS client owns
309is the ability to take an existing directory (and everything 309a lock on a Linux NFS server, which turned
310underneath it) in a ZFS filesystem and turn it into a sub-filesystem 310out to be specific to NFS v3 (which I really should have seen coming,
311of its own. One reason for wanting this is that a number of things 311since it involved NLM and lockd). Finding the NFS v4 client that
312are set and controlled on a per-filesyst…<li><a href=http://www.landley.net/notes-2023.html#28-10-2023 target=_blank rel=noopener>October 28, 2023</a> — <a href=http://www.landley.net/notes-2023.html>Rob Landley's Blog Thing for 2023</a><div>Oh good grief, two of my least favorite licensing people, Larry Rosen 312owns a lock is, depending on your perspective, either simpl…<li><a href=http://www.landley.net/notes-2023.html#28-10-2023 target=_blank rel=noopener>October 28, 2023</a> — <a href=http://www.landley.net/notes-2023.html>Rob Landley's Blog Thing for 2023</a><div>Oh good grief, two of my least favorite licensing people, Larry Rosen
313and Bradley Kuhn, are interacting on the OSI's license-discuss 313and Bradley Kuhn, are interacting on the OSI's license-discuss
314list where the're doing 314list where the're doing
315bad computer history and insisting that a guy Larry Rosen 315bad computer history and insisting that a guy Larry Rosen