events-backend: server-side implementation of local subscriber optimization

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-05-23 09:51:15 +02:00
parent b8be639b9a
commit 3a966aff5f
2 changed files with 51 additions and 10 deletions
+36 -3
View File
@@ -93,6 +93,16 @@ backend.add(
console.log(
`DEBUG: sub create req = ${subRes.status} ${subRes.statusText}`,
);
const subRes2 = await client.putSubscription(
{
path: { subscriptionId: 'abc' },
body: { topics: ['test'] },
},
{ token },
);
console.log(
`DEBUG: sub create req = ${subRes2.status} ${subRes2.statusText}`,
);
const poll = async () => {
const res = await client.getSubscriptionEvents(
@@ -111,11 +121,34 @@ backend.add(
};
poll();
const poll2 = async () => {
const res = await client.getSubscriptionEvents(
{
path: { subscriptionId: 'abc' },
},
{ token },
);
const data = res.status === 200 && (await res.json());
console.log(
`DEBUG: sub poll2 req = ${res.status} ${res.statusText}`,
data,
);
poll2();
};
poll2();
setTimeout(() => {
console.log(`DEBUG: publishing!`);
client.postEvent({
body: { event: { topic: 'test', payload: { foo: 'bar' } } },
});
client.postEvent(
{
body: {
event: { topic: 'test', payload: { foo: 'bar' } },
subscriptionIds: ['123'],
},
},
{ token },
);
}, 500);
});
},