Java Code Examples for org.redisson.api.RStream#readGroup()

The following examples show how to use org.redisson.api.RStream#readGroup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamExamples.java    From redisson-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    RStream<String, String> stream = redisson.getStream("test");
    stream.createGroup("testGroup");
    
    StreamMessageId id1 = stream.add("1", "1");
    StreamMessageId id2 = stream.add("2", "2");
    
    // contains 2 elements
    Map<StreamMessageId, Map<String, String>> map1 = stream.readGroup("testGroup", "consumer1");

    // ack messages
    stream.ack("testGroup", id1, id2);
    
    StreamMessageId id3 = stream.add("3", "3");
    StreamMessageId id4 = stream.add("4", "4");
    
    // contains next 2 elements
    Map<StreamMessageId, Map<String, String>> map2 = stream.readGroup("testGroup", "consumer2");

    PendingResult pi = stream.listPending("testGroup");
    
    redisson.shutdown();
}
 
Example 2
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateGroupMessageId() {
    RStream<String, String> stream = redisson.getStream("test");

    StreamMessageId id = stream.add("0", "0");
    
    stream.createGroup("testGroup");

    StreamMessageId id1 = stream.add("1", "1");
    System.out.println("id1 " + id1);
    StreamMessageId id2 = stream.add("2", "2");
    System.out.println("id2 " + id2);

    Map<StreamMessageId, Map<String, String>> s = stream.readGroup("testGroup", "consumer1");
    assertThat(s.size()).isEqualTo(2);
    
    stream.updateGroupMessageId("testGroup", id);
    
    Map<StreamMessageId, Map<String, String>> s2 = stream.readGroup("testGroup", "consumer2");
    assertThat(s2.size()).isEqualTo(2);
}
 
Example 3
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveConsumer() {
    RStream<String, String> stream = redisson.getStream("test");

    stream.add("0", "0");
    
    stream.createGroup("testGroup");
    
    StreamMessageId id1 = stream.add("1", "1");
    StreamMessageId id2 = stream.add("2", "2");

    Map<StreamMessageId, Map<String, String>> s = stream.readGroup("testGroup", "consumer1");
    assertThat(s.size()).isEqualTo(2);
    
    assertThat(stream.removeConsumer("testGroup", "consumer1")).isEqualTo(2);
    assertThat(stream.removeConsumer("testGroup", "consumer2")).isZero();
}
 
Example 4
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testClaimIds() throws InterruptedException {
    RStream<String, String> stream = redisson.getStream("test3");

    stream.add("0", "0");
    
    stream.createGroup("testGroup3");
    
    StreamMessageId id1 = stream.add("1", "1");
    StreamMessageId id2 = stream.add("2", "2");
    
    Map<StreamMessageId, Map<String, String>> s = stream.readGroup("testGroup3", "consumer1");
    assertThat(s.size()).isEqualTo(2);
    
    StreamMessageId id3 = stream.add("3", "33");
    StreamMessageId id4 = stream.add("4", "44");
    
    Map<StreamMessageId, Map<String, String>> s2 = stream.readGroup("testGroup3", "consumer2");
    assertThat(s2.size()).isEqualTo(2);
    
    List<StreamMessageId> res = stream.fastClaim("testGroup3", "consumer1", 1, TimeUnit.MILLISECONDS, id3, id4);
    assertThat(res.size()).isEqualTo(2);
    assertThat(res).containsExactly(id3, id4);
}
 
Example 5
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadGroupMulti() {
    RStream<String, String> stream1 = redisson.getStream("test1");
    RStream<String, String> stream2 = redisson.getStream("test2");

    StreamMessageId id01 = stream1.add("0", "0");
    StreamMessageId id02 = stream2.add("0", "0");
    
    stream1.createGroup("testGroup", id01);
    stream2.createGroup("testGroup", id02);
    
    StreamMessageId id11 = stream1.add("1", "1");
    StreamMessageId id12 = stream1.add("2", "2");
    StreamMessageId id13 = stream1.add("3", "3");
    StreamMessageId id21 = stream2.add("1", "1");
    StreamMessageId id22 = stream2.add("2", "2");
    StreamMessageId id23 = stream2.add("3", "3");
    
    Map<String, Map<StreamMessageId, Map<String, String>>> s2 = stream1.readGroup("testGroup", "consumer1", id11, Collections.singletonMap("test2", id21));
    assertThat(s2).isEmpty();
}
 
Example 6
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testClaim() {
    RStream<String, String> stream = redisson.getStream("test");

    stream.add("0", "0");
    
    stream.createGroup("testGroup");
    
    StreamMessageId id1 = stream.add("1", "1");
    StreamMessageId id2 = stream.add("2", "2");
    
    Map<StreamMessageId, Map<String, String>> s = stream.readGroup("testGroup", "consumer1");
    assertThat(s.size()).isEqualTo(2);
    
    StreamMessageId id3 = stream.add("3", "33");
    StreamMessageId id4 = stream.add("4", "44");
    
    Map<StreamMessageId, Map<String, String>> s2 = stream.readGroup("testGroup", "consumer2");
    assertThat(s2.size()).isEqualTo(2);
    
    Map<StreamMessageId, Map<String, String>> res = stream.claim("testGroup", "consumer1", 1, TimeUnit.MILLISECONDS, id3, id4);
    assertThat(res.size()).isEqualTo(2);
    assertThat(res.keySet()).containsExactly(id3, id4);
    for (Map<String, String> map : res.values()) {
        assertThat(map.keySet()).containsAnyOf("3", "4");
        assertThat(map.values()).containsAnyOf("33", "44");
    }
}
 
Example 7
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPendingRange() {
    RStream<String, String> stream = redisson.getStream("test");

    stream.add("0", "0");
    
    stream.createGroup("testGroup");
    
    StreamMessageId id1 = stream.add("11", "12");
    StreamMessageId id2 = stream.add("21", "22");
    
    Map<StreamMessageId, Map<String, String>> s = stream.readGroup("testGroup", "consumer1");
    assertThat(s.size()).isEqualTo(2);
    
    Map<StreamMessageId, Map<String, String>> pres = stream.pendingRange("testGroup", StreamMessageId.MIN, StreamMessageId.MAX, 10);
    assertThat(pres.keySet()).containsExactly(id1, id2);
    assertThat(pres.get(id1)).isEqualTo(Collections.singletonMap("11", "12"));
    assertThat(pres.get(id2)).isEqualTo(Collections.singletonMap("21", "22"));
    
    Map<StreamMessageId, Map<String, String>> pres2 = stream.pendingRange("testGroup", "consumer1", StreamMessageId.MIN, StreamMessageId.MAX, 10);
    assertThat(pres2.keySet()).containsExactly(id1, id2);
    assertThat(pres2.get(id1)).isEqualTo(Collections.singletonMap("11", "12"));
    assertThat(pres2.get(id2)).isEqualTo(Collections.singletonMap("21", "22"));
    
    Map<StreamMessageId, Map<String, String>> pres3 = stream.pendingRange("testGroup", "consumer2", StreamMessageId.MIN, StreamMessageId.MAX, 10);
    assertThat(pres3).isEmpty();
}
 
Example 8
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateEmpty() {
    RStream<String, String> stream = redisson.getStream("test");
    stream.createGroup("testGroup", StreamMessageId.ALL);
    stream.add("1", "2");
    
    Map<StreamMessageId, Map<String, String>> s = stream.readGroup("testGroup", "consumer1");
    assertThat(s).hasSize(1);
}
 
Example 9
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadGroup() {
    RStream<String, String> stream = redisson.getStream("test");

    StreamMessageId id0 = stream.add("0", "0");
    
    stream.createGroup("testGroup", id0);
    
    stream.add("1", "1");
    stream.add("2", "2");
    stream.add("3", "3");
    
    Map<StreamMessageId, Map<String, String>> s = stream.readGroup("testGroup", "consumer1");
    assertThat(s.values().iterator().next().keySet()).containsAnyOf("1", "2", "3");
    assertThat(s.size()).isEqualTo(3);

    stream.add("1", "1");
    stream.add("2", "2");
    stream.add("3", "3");
    
    Map<StreamMessageId, Map<String, String>> s1 = stream.readGroup("testGroup", "consumer1", 1);
    assertThat(s1.size()).isEqualTo(1);
    
    StreamMessageId id = stream.add("1", "1");
    stream.add("2", "2");
    stream.add("3", "3");
    
    Map<StreamMessageId, Map<String, String>> s2 = stream.readGroup("testGroup", "consumer1", id);
    assertThat(s2).isEmpty();
}
 
Example 10
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamConsumers() {
    RStream<String, String> stream = redisson.getStream("test1");
    
    StreamMessageId id1 = new StreamMessageId(12, 44);
    stream.createGroup("testGroup", id1);
    
    stream.add("1", "1");
    stream.add("2", "2");
    stream.add("3", "3");

    StreamMessageId id2 = new StreamMessageId(12, 44);
    stream.createGroup("testGroup2", id2);
    
    stream.add("1", "1");
    stream.add("2", "2");
    stream.add("3", "3");
    
    Map<StreamMessageId, Map<String, String>> map = stream.readGroup("testGroup", "consumer1");
    assertThat(map.size()).isEqualTo(6);
    
    List<StreamConsumer> s1 = stream.listConsumers("testGroup");
    assertThat(s1).hasSize(1);
    assertThat(s1.get(0).getName()).isEqualTo("consumer1");
    assertThat(s1.get(0).getPending()).isEqualTo(6);
    assertThat(s1.get(0).getIdleTime()).isLessThan(100L);

    Map<StreamMessageId, Map<String, String>> map2 = stream.readGroup("testGroup2", "consumer2");
    assertThat(map2.size()).isEqualTo(6);
    
    List<StreamConsumer> s2 = stream.listConsumers("testGroup2");
    assertThat(s2).hasSize(1);
    assertThat(s2.get(0).getName()).isEqualTo("consumer2");
    assertThat(s2.get(0).getPending()).isEqualTo(6);
    assertThat(s2.get(0).getIdleTime()).isLessThan(100L);

}
 
Example 11
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testAck() {
    RStream<String, String> stream = redisson.getStream("test");

    stream.add("0", "0");
    
    stream.createGroup("testGroup");
    
    StreamMessageId id1 = stream.add("1", "1");
    StreamMessageId id2 = stream.add("2", "2");
    
    Map<StreamMessageId, Map<String, String>> s = stream.readGroup("testGroup", "consumer1");
    assertThat(s.size()).isEqualTo(2);

    assertThat(stream.ack("testGroup", id1, id2)).isEqualTo(2);
}
 
Example 12
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 3 votes vote down vote up
@Test(expected = RedisException.class)
public void testRemoveGroup() {
    RStream<String, String> stream = redisson.getStream("test");

    stream.add("0", "0");
    
    stream.createGroup("testGroup");
    
    StreamMessageId id1 = stream.add("1", "1");
    StreamMessageId id2 = stream.add("2", "2");
    
    stream.removeGroup("testGroup");
    
    stream.readGroup("testGroup", "consumer1");
}
 
Example 13
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 3 votes vote down vote up
@Test
    public void testReadGroupBlocking() {
        RStream<String, String> stream = redisson.getStream("test");

        StreamMessageId id0 = stream.add("0", "0");
        
        stream.createGroup("testGroup", id0);
        
        stream.add("1", "1");
        stream.add("2", "2");
        stream.add("3", "3");

        Map<StreamMessageId, Map<String, String>> s = stream.readGroup("testGroup", "consumer1", 3, 5, TimeUnit.SECONDS);
        assertThat(s.values().iterator().next().keySet()).containsAnyOf("1", "2", "3");
        assertThat(s.size()).isEqualTo(3);

        stream.removeGroup("testGroup");
        
        stream.createGroup("testGroup", id0);
        
        stream.add("1", "1");
        stream.add("2", "2");
        stream.add("3", "3");

        RStream<String, String> stream2 = redisson.getStream("test2");
        
        StreamMessageId id1 = stream2.add("0", "0");
        
        stream2.createGroup("testGroup", id1);
        
//        Map<String, Map<StreamMessageId, Map<String, String>>> s2 = stream.readGroup("testGroup", "consumer1", 3, 5, TimeUnit.SECONDS, id0, Collections.singletonMap("test2", id1));
//        assertThat(s2.values().iterator().next().values().iterator().next().keySet()).containsAnyOf("1", "2", "3");
//        assertThat(s2.size()).isEqualTo(3);
    }