sonus21 / rqueue

Rqueue aka Redis Queue [Task Queue, Message Broker] for Spring framework
https://sonus21.github.io/rqueue
Apache License 2.0
337 stars 57 forks source link

Best practice of initializing a queue (producer only) #225

Closed stefan-g closed 4 months ago

stefan-g commented 5 months ago

I have 2 different instances. One instance produces jobs and one consumes it. It does only work correct when i register the queue manually by the manager. Is that the way how it should be?

@log4j2
@service
public class RQueueMessageService {

private final RqueueMessageEnqueuer rqueueMessageEnqueuer;
private final RqueueEndpointManager manager;

public RQueueMessageService(final RqueueMessageEnqueuer rqueueMessageEnqueuer, final RqueueEndpointManager manager) {
this.rqueueMessageEnqueuer = rqueueMessageEnqueuer;
this.manager = manager;
this.manager.registerQueue("import-job");
}

public void createJOB(ImportMessage message) {
rqueueMessageEnqueuer.enqueueWithRetry("import-job", message,3);
}

}
sonus21 commented 5 months ago

Hi @stefan-g Which version of Rqueue do you have?
In this doc, we've explained a different way to use it, https://sonus21.github.io/rqueue/producer-consumer

If you're using the same application code for producer and consumer in that case you don't have to call register queue method.

You can just rqueue.scheduler.enabled=false and rqueue.system.mode=PRODUCER in the producer application instance. In consumer you can let it be default behaviour.

A sample test app https://github.com/sonus21/rqueue/blob/a8cb236161eecb35f121544dc422e92c19ccc96e/rqueue-spring-boot-starter/src/test/java/com/github/sonus21/rqueue/spring/boot/tests/integration/ProducerOnlyTest.java#L53