Clean up Spring Data Redis pub/sub example

This commit is contained in:
David Morley 2016-03-17 06:09:47 -05:00
parent 6f2ee52550
commit 7c030c6965
12 changed files with 24 additions and 83 deletions

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sprint-data-redis</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>sprint-data-redis</artifactId>
<artifactId>spring-data-redis</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

View File

@ -1,8 +1,8 @@
package org.baeldung.spring.data.redis.config;
package com.baeldung.spring.data.redis.config;
import org.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
import org.baeldung.spring.data.redis.queue.RedisMessagePublisher;
import org.baeldung.spring.data.redis.queue.MessagePublisher;
import com.baeldung.spring.data.redis.queue.MessagePublisher;
import com.baeldung.spring.data.redis.queue.RedisMessagePublisher;
import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@ -11,9 +11,10 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.data.redis.serializer.GenericToStringSerializer;
@Configuration
@ComponentScan("org.baeldung.spring.data.redis")
@ComponentScan("com.baeldung.spring.data.redis")
public class RedisConfig {
@Bean
@ -25,6 +26,7 @@ public class RedisConfig {
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;
}

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.redis.model;
package com.baeldung.spring.data.redis.model;
import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.redis.queue;
package com.baeldung.spring.data.redis.queue;
public interface MessagePublisher {

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.redis.queue;
package com.baeldung.spring.data.redis.queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring.data.redis.queue;
package com.baeldung.spring.data.redis.queue;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
@ -14,6 +14,6 @@ public class RedisMessageSubscriber implements MessageListener {
public void onMessage(final Message message, final byte[] pattern) {
messageList.add(message.toString());
System.out.println("Message received: " + message.toString());
System.out.println("Message received: " + new String(message.getBody()));
}
}

View File

@ -1,6 +1,6 @@
package org.baeldung.spring.data.redis.repo;
package com.baeldung.spring.data.redis.repo;
import org.baeldung.spring.data.redis.model.Student;
import com.baeldung.spring.data.redis.model.Student;
import java.util.Map;

View File

@ -1,6 +1,6 @@
package org.baeldung.spring.data.redis.repo;
package com.baeldung.spring.data.redis.repo;
import org.baeldung.spring.data.redis.model.Student;
import com.baeldung.spring.data.redis.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;

View File

@ -1,8 +1,8 @@
package org.baeldung.spring.data.redis;
package com.baeldung.spring.data.redis;
import org.baeldung.spring.data.redis.config.RedisConfig;
import org.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
import org.baeldung.spring.data.redis.queue.RedisMessagePublisher;
import com.baeldung.spring.data.redis.config.RedisConfig;
import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
import com.baeldung.spring.data.redis.queue.RedisMessagePublisher;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,8 +1,7 @@
package org.baeldung.spring.data.redis.repo;
package com.baeldung.spring.data.redis.repo;
import org.baeldung.spring.data.redis.config.RedisConfig;
import org.baeldung.spring.data.redis.model.Student;
import org.junit.Before;
import com.baeldung.spring.data.redis.config.RedisConfig;
import com.baeldung.spring.data.redis.model.Student;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;