hasanaktasTR
hasanaktasTR
TtRPC
Created by hasanaktasTR on 10/21/2024 in #❓-help
How to use subscription with bullmq?
How can I process the messages in the queue with bullmq in the worker and publish them on the subscription side? I can't solve it in any way. My trpc server is published on my own nodejs server. What I want to do is as follows, but we can't use yield in eventlistener. What is the right way?
import { Queue, Worker } from "bullmq";

const sendMessage = publicProcedure
.mutation(async ({ ctx }) => {
const myQueue = new Queue(`match-message`, { connection:ctx.redis });
await myQueue.add('test', 'test message');
return true;
});


const onMessage = publicProcedure.subscription(async function* ({
signal,
input,
ctx,
}) {

const worker=new Worker(`match-message`, async (job) => {
return job.returnvalue as Message
},{
connection:ctx.redis
})
worker.on('completed', (job) => {
// yield message
})
if(signal?.aborted){
worker.close()
}


});
import { Queue, Worker } from "bullmq";

const sendMessage = publicProcedure
.mutation(async ({ ctx }) => {
const myQueue = new Queue(`match-message`, { connection:ctx.redis });
await myQueue.add('test', 'test message');
return true;
});


const onMessage = publicProcedure.subscription(async function* ({
signal,
input,
ctx,
}) {

const worker=new Worker(`match-message`, async (job) => {
return job.returnvalue as Message
},{
connection:ctx.redis
})
worker.on('completed', (job) => {
// yield message
})
if(signal?.aborted){
worker.close()
}


});
1 replies