DATAKV-68
+ merge channel and pattern into topic in the listener namespace
This commit is contained in:
@@ -155,7 +155,7 @@ template.convertAndSend("hello!", "world");]]></programlisting>
|
||||
<!-- the default ConnectionFactory -->
|
||||
<redis:listener-container>
|
||||
<!-- the method attribute can be skipped as the default method name is "handleMessage" -->
|
||||
<redis:listener ref="listener" method="handleMessage" channel="chatroom" />
|
||||
<redis:listener ref="listener" method="handleMessage" topic="chatroom" />
|
||||
</redis:listener-container>
|
||||
|
||||
<bean class="redisexample.DefaultMessageDelegate"/>
|
||||
@@ -177,7 +177,7 @@ template.convertAndSend("hello!", "world");]]></programlisting>
|
||||
<bean id="redisContainer" class="org.springframework.data.keyvalue.redis.listener.RedisMessageListenerContainer">
|
||||
<property name="connectionFactory" ref="connectionFactory"/>
|
||||
<property name="messageListeners">
|
||||
<lineannotation><!-- map of listeners and their associated topics (channels or topics) --></lineannotation>
|
||||
<lineannotation><!-- map of listeners and their associated topics (channels or/and patterns) --></lineannotation>
|
||||
<map>
|
||||
<emphasis role="bold"><entry key-ref="messageListener"></emphasis>
|
||||
<bean class="org.springframework.data.keyvalue.redis.listener.ChannelTopic">
|
||||
|
||||
@@ -117,26 +117,15 @@ class RedisListenerContainerParser extends AbstractSimpleBeanDefinitionParser {
|
||||
// assemble topics
|
||||
Collection<Topic> topics = new ArrayList<Topic>();
|
||||
|
||||
// get channels
|
||||
String channels = element.getAttribute("channel");
|
||||
if (StringUtils.hasText(channels)) {
|
||||
String[] array = StringUtils.delimitedListToStringArray(channels, " ");
|
||||
// get topic
|
||||
String xTopics = element.getAttribute("topic");
|
||||
if (StringUtils.hasText(xTopics)) {
|
||||
String[] array = StringUtils.delimitedListToStringArray(xTopics, " ");
|
||||
|
||||
for (String string : array) {
|
||||
topics.add(new ChannelTopic(string));
|
||||
topics.add(string.contains("*") ? new PatternTopic(string) : new ChannelTopic(string));
|
||||
}
|
||||
}
|
||||
|
||||
// get patterns
|
||||
String patterns = element.getAttribute("pattern");
|
||||
if (StringUtils.hasText(patterns)) {
|
||||
String[] array = StringUtils.delimitedListToStringArray(patterns, " ");
|
||||
|
||||
for (String string : array) {
|
||||
topics.add(new PatternTopic(string));
|
||||
}
|
||||
}
|
||||
|
||||
ret[0] = builder.getBeanDefinition();
|
||||
ret[1] = topics;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.data.keyvalue.redis.listener;
|
||||
|
||||
/**
|
||||
* Topic describing a channel.
|
||||
* Channel topic implementation (maps to a Redis channel).
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@@ -34,9 +34,9 @@ public class ChannelTopic implements Topic {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the channel name.
|
||||
* Returns the topic name.
|
||||
*
|
||||
* @return channel name
|
||||
* @return topic name
|
||||
*/
|
||||
public String getTopic() {
|
||||
return channelName;
|
||||
|
||||
@@ -110,19 +110,12 @@ and stop as soon as possible.
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="channel" type="xsd:string">
|
||||
<xsd:attribute name="topic" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The channel(s) to which the listener is subscribed. Multiple values can be specified
|
||||
by separating them with spaces.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="pattern" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The pattern(s) matching the channels to which the listener is subscribed. Multiple values can be specified
|
||||
by separating them with spaces.
|
||||
The topics(s) to which the listener is subscribed. Can be (in Redis terminology) a
|
||||
channel or/and a pattern. Multiple values can be specified by separating them with
|
||||
spaces. Patterns can be specified by using the '*' character.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
|
||||
<redis:listener-container topic-serializer="serializer">
|
||||
<!-- default handle method -->
|
||||
<redis:listener ref="testBean1" channel="z1 z2" pattern="x*"/>
|
||||
<redis:listener ref="testBean1" topic="z1 z2 x*"/>
|
||||
<!-- channel subscription only -->
|
||||
<redis:listener ref="testBean1" method="anotherHandle" channel="x1" serializer="serializer"/>
|
||||
<redis:listener ref="testBean2" channel="exception"/>
|
||||
<redis:listener ref="testBean1" method="anotherHandle" topic="x1" serializer="serializer"/>
|
||||
<redis:listener ref="testBean2" topic="exception"/>
|
||||
</redis:listener-container>
|
||||
|
||||
<bean id="testBean1" class="org.springframework.data.keyvalue.redis.listener.adapter.RedisMDP"/>
|
||||
|
||||
Reference in New Issue
Block a user