diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-10-31 10:17:43 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-10-31 10:17:43 +0100 |
| commit | ae24d9a8869c497537839f330384cbadb2cf687c (patch) | |
| tree | 79184f1d1db6f0b8e2f7aad3a262b3a2bccdde58 /public/simple-server-sent-events-based-pubsub-server.html | |
| parent | 409dfae3983b55ffa469a556683fab4ec70b1e99 (diff) | |
| download | mitjafelicijan.com-ae24d9a8869c497537839f330384cbadb2cf687c.tar.gz | |
Updated theme
Diffstat (limited to 'public/simple-server-sent-events-based-pubsub-server.html')
| -rwxr-xr-x | public/simple-server-sent-events-based-pubsub-server.html | 16 |
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> | |||
| 22 | to 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 | 22 | to 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 |
| 23 | simple. We have subscribers that receive messages, and we have publishers that | 23 | simple. We have subscribers that receive messages, and we have publishers that |
| 24 | create and post messages. Similar model is also well know pattern that works on | 24 | create and post messages. Similar model is also well know pattern that works on |
| 25 | a 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 | 25 | a 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 |
| 27 | for delivering messages,<li>if consumer wants to receive messages from a topic, producer and consumer | 27 | for delivering messages,<li>if consumer wants to receive messages from a topic, producer and consumer |
| 28 | topics 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 | 28 | topics 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> | |||
| 32 | opens a long-running connection between the client and the server so make sure | 32 | opens a long-running connection between the client and the server so make sure |
| 33 | if your setup is load balanced that the load balancer in this case can have | 33 | if your setup is load balanced that the load balancer in this case can have |
| 34 | long 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 | 34 | long 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 |
| 35 | page</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 | 35 | page</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> |
| 37 | for 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 | 37 | for 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 |
| 38 | automatically in case of a connection interrupt (bug)<li>Reportedly, CORS in EventSource is currently supported in Firefox 10+, Opera | 38 | automatically 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 | |||
| 55 | Events</a> | 55 | Events</a> |
| 56 | which 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 | 56 | which 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 |
| 57 | ones. For debugging server events add <code>console.log</code> to <code>server.js</code> code and | 57 | ones. For debugging server events add <code>console.log</code> to <code>server.js</code> code and |
| 58 | print 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 | 58 | print 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 |
| 60 | get started and we will use already written SSE library for node | 60 | get 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> </body> | 305 | </span></span><span style=display:flex><span> </body> |
| 306 | </span></span><span style=display:flex><span> | 306 | </span></span><span style=display:flex><span> |
| 307 | </span></span><span style=display:flex><span></html> | 307 | </span></span><span style=display:flex><span></html> |
| 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 |
| 309 | is the ability to take an existing directory (and everything | 309 | a lock on a Linux NFS server, which turned |
| 310 | underneath it) in a ZFS filesystem and turn it into a sub-filesystem | 310 | out to be specific to NFS v3 (which I really should have seen coming, |
| 311 | of its own. One reason for wanting this is that a number of things | 311 | since it involved NLM and lockd). Finding the NFS v4 client that |
| 312 | are 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 | 312 | owns 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 |
| 313 | and Bradley Kuhn, are interacting on the OSI's license-discuss | 313 | and Bradley Kuhn, are interacting on the OSI's license-discuss |
| 314 | list where the're doing | 314 | list where the're doing |
| 315 | bad computer history and insisting that a guy Larry Rosen | 315 | bad computer history and insisting that a guy Larry Rosen |
