agorapulse / micronaut-worker

Micronaut Worker
https://agorapulse.github.io/micronaut-worker
6 stars 2 forks source link

Looking for some examples with Redis queue #21

Open roxrook opened 2 years ago

roxrook commented 2 years ago

Can you guys provide some examples on how to configure Redis queue with and without YAML? Thanks!

musketyr commented 2 years ago

Hi. Redis integration is pretty simple. you only need two things:

1) Redis dependency

implementation 'com.agorapulse:micronaut-worker-queues-redis:1.2.1-micronaut-3.0'

2) Redis URI which can be set with REDIS_URI environment property or redis.url in the configuration file

redis:
  uri: redis://...

Then you create a job with consumer and producer:

public class MyJob {

    public Publisher<String> producerMethod() {
        // produce messages into queue
    }

    public void consumerMethod(String message) {
        // do something with message
    }

}

I've used String in the example, but you can use any object which can be de/serialized to JSON.

see more https://agorapulse.github.io/micronaut-worker/#_jobs_using_queue

roxrook commented 2 years ago

Thanks. My Redis instances also requires username, password and ssl. Besides I want to configure the correct size for connection pool and share it with other business logic as a singleton so I'm wondering if there is a way to configure it in code?

musketyr commented 2 years ago

Please, check the Micronaut Redis configuration for further information. They are read from redis. configuration properties.

https://micronaut-projects.github.io/micronaut-redis/latest/api/io/micronaut/configuration/lettuce/DefaultRedisConfiguration.html