# day 23 > jornal **Published by:** [0xea99](https://paragraph.com/@0xea990ae72939b8751cb680919c6b64a05b8e1451/) **Published on:** 2025-05-01 **URL:** https://paragraph.com/@0xea990ae72939b8751cb680919c6b64a05b8e1451/day-23 ## Content the only part in upstash docs about pubsub - scary.. high priority to switch out this service if PoC passeshttps://upstash.com/docs/redis/features/restapi#subscribe-%26-publish-commandsi subscribed to the "chat" channel using curl from the terminal and it got logged by upstash - ok so far so goodwhen i pushed a "lol" message to chat channel using the upstash CLI (a tab in the upstash web app), it printed 1 which means there is 1 client that received the messagethe logs showing both subscribe and publish being loggedterminal printing out both the subscribe and message SSE; the pubsub feature of upstash redis is handled by sse connection; can use upstash redis for pubsub { try { const response = await fetch(process.env.NEXT_PUBLIC_UPSTASH_SSE_URL + '/subscribe/trade_events', { method: 'GET', credentials: 'include', // Include cookies and auth headers: { 'Accept': 'text/event-stream', 'Cache-Control': 'no-cache', // Add any custom headers you need here 'Authorization': 'Bearer ' + process.env.NEXT_PUBLIC_UPSTASH_SSE_TOKEN, }, signal: abortController.signal, // Add abort signal }); if (!response.ok) { throw new Error(`Failed to connect to SSE: ${response.status}`); } // Get response body as a ReadableStream const reader = response.body?.getReader(); if (!reader) { throw new Error('Response body is not readable'); } // Manage connection state setError(null); console.log('Upstash SSE connection established successfully'); // Process the stream const decoder = new TextDecoder(); let buffer = ''; while (true) { const { done, value } = await reader.read(); if (done) { console.log('SSE connection closed by server'); break; } // Decode the chunk and add it to our buffer buffer += decoder.decode(value, { stream: true }); // Process complete events in the buffer const lines = buffer.split('\n\n'); buffer = lines.pop() || ''; // Keep the last incomplete chunk for (const eventBlock of lines) { ... } } catch { ... } } // Start the connection connectWithFetch(); // Return cleanup function return () => { console.log('Aborting custom SSE connection'); abortController.abort(); };"> // Custom SSE implementation using fetch const connectWithFetch = async () => { try { const response = await fetch(process.env.NEXT_PUBLIC_UPSTASH_SSE_URL + '/subscribe/trade_events', { method: 'GET', credentials: 'include', // Include cookies and auth headers: { 'Accept': 'text/event-stream', 'Cache-Control': 'no-cache', // Add any custom headers you need here 'Authorization': 'Bearer ' + process.env.NEXT_PUBLIC_UPSTASH_SSE_TOKEN, }, signal: abortController.signal, // Add abort signal }); if (!response.ok) { throw new Error(`Failed to connect to SSE: ${response.status}`); } // Get response body as a ReadableStream const reader = response.body?.getReader(); if (!reader) { throw new Error('Response body is not readable'); } // Manage connection state setError(null); console.log('Upstash SSE connection established successfully'); // Process the stream const decoder = new TextDecoder(); let buffer = ''; while (true) { const { done, value } = await reader.read(); if (done) { console.log('SSE connection closed by server'); break; } // Decode the chunk and add it to our buffer buffer += decoder.decode(value, { stream: true }); // Process complete events in the buffer const lines = buffer.split('\n\n'); buffer = lines.pop() || ''; // Keep the last incomplete chunk for (const eventBlock of lines) { ... } } catch { ... } } // Start the connection connectWithFetch(); // Return cleanup function return () => { console.log('Aborting custom SSE connection'); abortController.abort(); };the sse connection gets a bit messy if we need to add custom auth headers because we can't use the EventSource API.cursor claude 3.7 recommendations for adding custom auth headersopted for option 2 to get it working but need to go for option 1 to not expose jwt to clienttrello day 23 ## Publication Information - [0xea99](https://paragraph.com/@0xea990ae72939b8751cb680919c6b64a05b8e1451/): Publication homepage - [All Posts](https://paragraph.com/@0xea990ae72939b8751cb680919c6b64a05b8e1451/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@0xea990ae72939b8751cb680919c6b64a05b8e1451): Subscribe to updates ## Optional - [Collect as NFT](https://paragraph.com/@0xea990ae72939b8751cb680919c6b64a05b8e1451/day-23): Support the author by collecting this post - [View Collectors](https://paragraph.com/@0xea990ae72939b8751cb680919c6b64a05b8e1451/day-23/collectors): See who has collected this post