title: Spring-boot Redis JMS JUnit
body: <p>I am using Redis Server for message broker in my spring boot application.
  Is there any simple way to Junit my publish and receive API?</p>
  <p>e.g :</p>
  <p>Publisher :</p>
  <pre><code>public String publish(Object domainObj) {
  
      template.convertAndSend(topic.getTopic(), domainObj.toString());
      return &quot;Event Published&quot;;
  }
  </code></pre>
  <p>Receiver :</p>
  <p>public class Receiver implements MessageListener {</p>
  <pre><code>@Override
  public void onMessage(Message message, byte[] bytes) {
  
      System.out.println(&quot;Consumed Message {}&quot; + message);
  
  }
  </code></pre>
  <p>}</p>
  <p>I am using <code>JedisConnectionFactory</code> and <code>RedisMessageListenerContainer</code> and <code>RedisTemplate</code> for my implementation</p>
  <pre><code>@Configuration
  @EnableRedisRepositories
  public class RedisConfig {
  
      @Bean
      public JedisConnectionFactory connectionFactory() {
          RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
          configuration.setHostName(&quot;localhost&quot;);
          configuration.setPort(6379);
          return new JedisConnectionFactory(configuration);
      }
  
      @Bean
      public RedisTemplate&lt;String, Object&gt; template() {
          RedisTemplate&lt;String, Object&gt; template = new RedisTemplate&lt;&gt;();
          template.setConnectionFactory(connectionFactory());
          template.setKeySerializer(new StringRedisSerializer());
          template.setHashKeySerializer(new StringRedisSerializer());
          template.setHashKeySerializer(new JdkSerializationRedisSerializer());
          template.setValueSerializer(new JdkSerializationRedisSerializer());
          template.setEnableTransactionSupport(true);
          template.afterPropertiesSet();
          return template;
      }
  
      @Bean
      public ChannelTopic topic() {
          return new ChannelTopic(&quot;common-channel&quot;);
      }
  
      @Bean
      public MessageListenerAdapter messageListenerAdapter() {
          return new MessageListenerAdapter(new Receiver());
      }
  
      @Bean
      public RedisMessageListenerContainer redisMessageListenerContainer() {
          RedisMessageListenerContainer container = new RedisMessageListenerContainer();
          container.setConnectionFactory(connectionFactory());
          container.addMessageListener(messageListenerAdapter(), topic());
          return container;
      }
  </code></pre>