use of org.springframework.data.redis.listener.Topic in project camel by apache.
the class RedisConsumerTest method registerConsumerForTwoChannelTopics.
@Test
public void registerConsumerForTwoChannelTopics() throws Exception {
ArgumentCaptor<Collection> collectionCaptor = ArgumentCaptor.forClass(Collection.class);
verify(listenerContainer).addMessageListener(any(MessageListener.class), collectionCaptor.capture());
Collection<ChannelTopic> topics = collectionCaptor.getValue();
Iterator<ChannelTopic> topicIterator = topics.iterator();
Topic firstTopic = topicIterator.next();
Topic twoTopic = topicIterator.next();
assertEquals("one", firstTopic.getTopic());
assertEquals("two", twoTopic.getTopic());
}
use of org.springframework.data.redis.listener.Topic in project camel by apache.
the class RedisConsumer method toTopics.
private Collection<Topic> toTopics(String channels) {
String[] channelsArrays = channels.split(",");
List<Topic> topics = new ArrayList<>();
for (String channel : channelsArrays) {
String name = channel.trim();
if (Command.PSUBSCRIBE.equals(redisConfiguration.getCommand())) {
topics.add(new PatternTopic(name));
} else if (Command.SUBSCRIBE.equals(redisConfiguration.getCommand())) {
topics.add(new ChannelTopic(name));
} else {
throw new IllegalArgumentException("Unsupported Command " + redisConfiguration.getCommand());
}
}
return topics;
}
use of org.springframework.data.redis.listener.Topic in project spring-integration by spring-projects.
the class RedisInboundChannelAdapter method onInit.
@Override
protected void onInit() {
super.onInit();
boolean hasTopics = false;
if (this.topics != null) {
Assert.noNullElements(this.topics, "'topics' may not contain null elements.");
hasTopics = true;
}
boolean hasPatterns = false;
if (this.topicPatterns != null) {
Assert.noNullElements(this.topicPatterns, "'topicPatterns' may not contain null elements.");
hasPatterns = true;
}
Assert.state(hasTopics || hasPatterns, "at least one topic or topic pattern is required for subscription.");
if (this.messageConverter instanceof BeanFactoryAware) {
((BeanFactoryAware) this.messageConverter).setBeanFactory(this.getBeanFactory());
}
MessageListenerDelegate delegate = new MessageListenerDelegate();
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
adapter.setSerializer(this.serializer);
List<Topic> topicList = new ArrayList<Topic>();
if (hasTopics) {
for (String topic : this.topics) {
topicList.add(new ChannelTopic(topic));
}
}
if (hasPatterns) {
for (String pattern : this.topicPatterns) {
topicList.add(new PatternTopic(pattern));
}
}
adapter.afterPropertiesSet();
this.container.addMessageListener(adapter, topicList);
this.container.afterPropertiesSet();
}
Aggregations