{"id":16179160,"url":"https://github.com/jonashackt/spring-reactive-redis-messaging","last_synced_at":"2025-10-23T22:59:20.792Z","repository":{"id":41184486,"uuid":"155239602","full_name":"jonashackt/spring-reactive-redis-messaging","owner":"jonashackt","description":"Example project showing how to interact with Redis using Spring Boot","archived":false,"fork":false,"pushed_at":"2025-03-05T01:36:59.000Z","size":83,"stargazers_count":15,"open_issues_count":7,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-05T02:28:23.218Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonashackt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-29T15:54:50.000Z","updated_at":"2025-03-05T01:36:52.000Z","dependencies_parsed_at":"2024-01-19T23:24:00.893Z","dependency_job_id":"635676cf-3727-448c-a0fc-b6ce3eafe4b2","html_url":"https://github.com/jonashackt/spring-reactive-redis-messaging","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fspring-reactive-redis-messaging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fspring-reactive-redis-messaging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fspring-reactive-redis-messaging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fspring-reactive-redis-messaging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonashackt","download_url":"https://codeload.github.com/jonashackt/spring-reactive-redis-messaging/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243810850,"owners_count":20351596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T05:25:41.416Z","updated_at":"2025-10-23T22:59:15.756Z","avatar_url":"https://github.com/jonashackt.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"spring-reactive-redis-messaging\n======================================================================================\n[![Build Status](https://github.com/jonashackt/spring-reactive-redis-messaging/workflows/build/badge.svg)](https://github.com/jonashackt/spring-reactive-redis-messaging/actions)\n[![renovateenabled](https://img.shields.io/badge/renovate-enabled-yellow)](https://renovatebot.com)\n\nExample project showing how to interact with Redis using Spring Boot \n\n## HowTo\n\nInspired by https://spring.io/guides/gs/spring-data-reactive-redis/\n\nGo to https://start.spring.io/ and choose `Lombok`, `Reactive Web`, `Reactive Redis`.\n\nThe Testcase [CoffeeControllerTest.java](src/test/java/de/jonashackt/springredis/controller/CoffeeControllerTest.java) uses [testcontainers](https://www.testcontainers.org/) framework to leverage [redis](https://redis.io/) as a broker. Just run it, testcontainers will take care of firing up redis with [Docker](https://www.docker.com/) (just be sure to have Docker installed).\n\nIf you want to run the [SpringredisApplication.java](src/main/java/de/jonashackt/springredis/SpringredisApplication.java) be sure to fire up redis with:\n\n```\ndocker-compose up\n```\n\n### Implementing Reactive Messaging with Redis\n\nSee https://docs.spring.io/spring-data/data-redis/docs/2.1.1.RELEASE/reference/html/#redis:reactive\n\n##### ReactiveRedisConnectionFactory\n\nFirst we´ll need to configure Spring to [connect reactively to Redis with the ReactiveRedisConnectionFactory](https://docs.spring.io/spring-data/data-redis/docs/2.1.1.RELEASE/reference/html/#redis:reactive:connectors:lettuce) with Lettuce behind the scenes:\n\n```\n    @Bean\n    public ReactiveRedisConnectionFactory connectionFactory() {\n        return new LettuceConnectionFactory(\"localhost\", 6379);\n    }\n```\n\n##### ReactiveRedisTemplate\n\nInteraction with Redis in reactive use cases is abstracted in Spring Data by ReactiveRedisTemplate. So we need to initialize a Bean:\n\n```\n    @Bean\n    public ReactiveRedisTemplate\u003cString, String\u003e reactiveRedisTemplate(ReactiveRedisConnectionFactory factory) {\n        return new ReactiveRedisTemplate\u003c\u003e(factory, RedisSerializationContext.string());\n    }\n```\n\n##### Have a look into Redis PubSub\n\nOnly if one uses channels and subscribes to it on Redis, these channels are present (see `Understanding channels` in https://redisgreen.net/blog/pubsub-howto/).\n\nTo see the current channels in the Redis Docker container, check:\n\n```\ndocker exec -it redisContainerName sh\n\nredis-cli\n\npubsub channels\n``` \n\n\n### REST endpoints\n\nSpring Reactive WebClient: https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#webtestclient-tests\n\nWe need to use a curl / Postman / httpie to open up a HTTP connection to retrieve Server Side Events (SSE) from our channel subscriber:\n\n```\ncurl -v http://localhost:8080/message/coffees\n```\n\nNow messages could be retrieved from the Redis Pub/Sub channel `coffees:queue`.\n\nOn a second terminal windows we can now publish messages to Redis :\n\n```\nhttp POST http://localhost:8080/message/coffee/fooBarCoffee\n```\n\nSee https://developer.okta.com/blog/2018/09/24/reactive-apis-with-spring-webflux#the-web-the-final-frontier for more details on how to implement Spring Webflux style REST endpoints.\n\n\n# Links\n\n### Redis\n\nhttps://github.com/eugenp/tutorials/blob/master/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/reactive/redis/template/RedisTemplateListOpsIntegrationTest.java\n\nhttps://spring.io/guides/gs/messaging-redis/\n\nhttps://www.baeldung.com/spring-data-redis-pub-sub\n\n\n### Redis Reactive Messaging\n\nhttps://spring.io/guides/gs/spring-data-reactive-redis/\n\nhttps://docs.spring.io/spring-data/data-redis/docs/2.1.1.RELEASE/reference/html/#redis:reactive\n\nhttps://www.baeldung.com/java-redis-lettuce\n\n\n### RabbitMQ / AMQP Messaging\n\nhttps://www.baeldung.com/spring-amqp-reactive\n\n\n### Reactive WebFlux Stack\n\nhttps://developer.okta.com/blog/2018/09/24/reactive-apis-with-spring-webflux#the-web-the-final-frontier\n\nhttps://spring.io/guides/gs/reactive-rest-service/\n\nhttps://www.baeldung.com/spring-5-webclient\n\nhttps://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#webtestclient-tests\n\nhttps://dzone.com/articles/reactive-programming-with-spring-webflux\n\nhttps://www.baeldung.com/spring-5-functional-web\n\nhttps://medium.com/@cheron.antoine/tuto-building-a-reactive-restful-api-with-spring-webflux-java-258fd4dbae41\n\nhttps://stackoverflow.com/questions/50740795/how-to-wait-for-all-requests-to-complete-with-spring-5-webclient\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashackt%2Fspring-reactive-redis-messaging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonashackt%2Fspring-reactive-redis-messaging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashackt%2Fspring-reactive-redis-messaging/lists"}