Search in sources :

Example 71 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageStoreTests method testAddAndRemoveMessagesFromMessageGroup.

@Test
@RedisAvailable
public void testAddAndRemoveMessagesFromMessageGroup() throws Exception {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore messageStore = new RedisMessageStore(jcf);
    String groupId = "X";
    List<Message<?>> messages = new ArrayList<Message<?>>();
    for (int i = 0; i < 25; i++) {
        Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
        messageStore.addMessagesToGroup(groupId, message);
        messages.add(message);
    }
    messageStore.removeMessagesFromGroup(groupId, messages);
    MessageGroup group = messageStore.getMessageGroup(groupId);
    assertEquals(0, group.size());
    messageStore.removeMessageGroup("X");
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ArrayList(java.util.ArrayList) MessageGroup(org.springframework.integration.store.MessageGroup) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 72 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageStoreTests method testAddStringMessage.

@Test
@RedisAvailable
public void testAddStringMessage() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Message<String> stringMessage = new GenericMessage<String>("Hello Redis");
    Message<String> storedMessage = store.addMessage(stringMessage);
    assertNotSame(stringMessage, storedMessage);
    assertEquals("Hello Redis", storedMessage.getPayload());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 73 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageStoreTests method testAddAndGetWithPrefix.

@SuppressWarnings("unchecked")
@Test
@RedisAvailable
public void testAddAndGetWithPrefix() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf, "foo");
    Message<String> stringMessage = new GenericMessage<String>("Hello Redis");
    store.addMessage(stringMessage);
    Message<String> retrievedMessage = (Message<String>) store.getMessage(stringMessage.getHeaders().getId());
    assertNotNull(retrievedMessage);
    assertEquals("Hello Redis", retrievedMessage.getPayload());
    StringRedisTemplate template = createStringRedisTemplate(getConnectionFactoryForTest());
    BoundValueOperations<String, String> ops = template.boundValueOps("foo" + "MESSAGE_" + stringMessage.getHeaders().getId());
    assertNotNull(ops.get());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 74 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageStoreTests method testAddSerializableObjectMessage.

@Test
@RedisAvailable
public void testAddSerializableObjectMessage() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Address address = new Address();
    address.setAddress("1600 Pennsylvania Av, Washington, DC");
    Person person = new Person(address, "Barak Obama");
    Message<Person> objectMessage = new GenericMessage<Person>(person);
    Message<Person> storedMessage = store.addMessage(objectMessage);
    assertNotSame(objectMessage, storedMessage);
    assertEquals("Barak Obama", storedMessage.getPayload().getName());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 75 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisStoreInboundChannelAdapterIntegrationTests method testListInboundConfiguration.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public void testListInboundConfiguration() throws Exception {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.prepareList(jcf);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("list-inbound-adapter.xml", this.getClass());
    SourcePollingChannelAdapter spca = context.getBean("listAdapter", SourcePollingChannelAdapter.class);
    spca.start();
    QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
    Message<Integer> message = (Message<Integer>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(Integer.valueOf(13), message.getPayload());
    // poll again, should get the same stuff
    message = (Message<Integer>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(Integer.valueOf(13), message.getPayload());
    this.deletePresidents(jcf);
    context.close();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)95 Test (org.junit.Test)83 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)62 GenericMessage (org.springframework.messaging.support.GenericMessage)22 BeanFactory (org.springframework.beans.factory.BeanFactory)19 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)17 MessageGroup (org.springframework.integration.store.MessageGroup)14 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)13 ArrayList (java.util.ArrayList)12 Message (org.springframework.messaging.Message)10 Properties (java.util.Properties)9 ApplicationContext (org.springframework.context.ApplicationContext)9 List (java.util.List)8 DefaultRedisList (org.springframework.data.redis.support.collections.DefaultRedisList)8 RedisList (org.springframework.data.redis.support.collections.RedisList)8 RedisConnection (org.springframework.data.redis.connection.RedisConnection)7 DefaultRedisZSet (org.springframework.data.redis.support.collections.DefaultRedisZSet)7 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)6 TypedTuple (org.springframework.data.redis.core.ZSetOperations.TypedTuple)6 LiteralExpression (org.springframework.expression.common.LiteralExpression)6