Spring Data Redis Messaging - PubSub example | Spring Boot » grokonez

Spring Data Redis Messaging - PubSub example | Spring Boot » grokonez

Way to implement Redis Messaging- PubSub with Spring Boot - Spring Data Redis examle - Spring Data Redis Pubsub example - Spring Redis Messaging example - Spring Boot Redis Pubsub

https://grokonez.com/spring-framework/spring-boot/spring-data-redis-messaging-pubsub-spring-boot-spring-data-redis-example

Spring Data Redis Messaging – PubSub example | Spring Boot

The previous post introduces way to do Redis CRUD Operations. In this tutorial, we're gonna look at how to implement Redis Messaging- PubSub with Spring Boot.

Related Post: Spring Data Redis CRUD Operations example with Spring Boot

I. Technology

- Java 1.8 - Maven 3.3.9 - Spring Tool Suite – Version 3.9.0.RELEASE - Spring Boot: 1.5.9.RELEASE

II. Spring Data Redis Messaging - PubSub

1. Overview

Spring Data provides dedicated messaging integration for Redis that can be roughly divided into two areas of functionality: production (or publication) and consumption (or subscription) of messages.
  • Publisher doesn't know specific subscribers to send messages to. Instead, Publisher specifies channel.
  • Subscriber receives messages from one or more topics, without knowledge of Publisher.

    2. Maven Dependency

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

    3. Redis Configuration

    We need:
  • connection factory -> JedisConnectionFactory
  • a channel -> ChannelTopic
  • a template for publisher to publish messages -> RedisTemplate
  • a message listener for consumer to consume messages -> RedisMessageListenerContainer
    @Bean
    JedisConnectionFactory jedisConnectionFactory() {
      return new JedisConnectionFactory();
    }
    
    

@Bean public RedisTemplate<String, Object> redisTemplate() { final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>(); template.setConnectionFactory(jedisConnectionFactory()); template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class)); return template; }

@Bean MessageListenerAdapter messageListener() { return new MessageListenerAdapter(new CustomerInfoSubscriber()); }

@Bean RedisMessageListenerContainer redisContainer() { final RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(jedisConnectionFactory()); container.addMessageListener(messageListener(), topic()); container.setTaskExecutor(Executors.newFixedThreadPool(4)); return container; }

@Bean CustomerInfoPublisher redisPublisher() { return new RedisCustomerInfoPublisher(redisTemplate(), topic()); }

@Bean ChannelTopic topic() { return new ChannelTopic("pubsub:jsa-channel"); } We can also supply an executor within RedisMessageListenerContainer for asynch manner of messages.

https://grokonez.com/spring-framework/spring-boot/spring-data-redis-messaging-pubsub-spring-boot-spring-data-redis-example

Spring Data Redis Messaging – PubSub example | Spring Boot

springboot springdata redis publisher subscriber

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Redis Transactions & Long-Running Lua Scripts

Redis Lua scripting is the popularly recommended approach for handling transactions. Learn the common Lua Scripts error and how to handle for sentinel systems. Redis offers two mechanisms for handling transactions – MULTI/EXEC based transactions and Lua scripts evaluation. Redis Lua scripting is the recommended approach and is fairly popular in usage.

Spring Data with Redis Publisher and Subscriber Messaging example

You will learn how to integrate with spring data with Redis Publisher and Subscriber Messaging. GitHub Link: https://github.com/shameed1910/springboot-redis-...

Angular 10 SpringBoot MongoDB CRUD Example - using SpringData & Atlas MongoDB

In the tutorial, I will introduce how to implement a "Angular 10 SpringBoot MongoDB CRUD Example" with the supporting of SpringData MongoDB

Spring Data Redis CRUD Operations example with Spring Boot » grokonez

Spring Boot Redis example - Spring Data Redis example - how to do Redis CRUD Operations with Spring Boot using Spring Data Redis.

Spring Data Redis CRUD Operations example with Spring Boot » grokonez

Spring Boot Redis example - Spring Data Redis example - how to do Redis CRUD Operations with Spring Boot using Spring Data Redis.