DATAKV-68

+ merge channel and pattern into topic in the listener namespace
This commit is contained in:
Costin Leau
2011-04-22 17:49:29 +03:00
parent 718d60484c
commit 050e461a8e
5 changed files with 17 additions and 35 deletions

View File

@@ -155,7 +155,7 @@ template.convertAndSend("hello!", "world");]]></programlisting>
&lt;!-- the default ConnectionFactory --&gt;
&lt;redis:listener-container&gt;
&lt;!-- the method attribute can be skipped as the default method name is "handleMessage" --&gt;
&lt;redis:listener ref="listener" method="handleMessage" channel="chatroom" /&gt;
&lt;redis:listener ref="listener" method="handleMessage" topic="chatroom" /&gt;
&lt;/redis:listener-container&gt;
&lt;bean class="redisexample.DefaultMessageDelegate"/&gt;
@@ -177,7 +177,7 @@ template.convertAndSend("hello!", "world");]]></programlisting>
&lt;bean id="redisContainer" class="org.springframework.data.keyvalue.redis.listener.RedisMessageListenerContainer"&gt;
&lt;property name="connectionFactory" ref="connectionFactory"/&gt;
&lt;property name="messageListeners"&gt;
<lineannotation>&lt;!-- map of listeners and their associated topics (channels or topics) --&gt;</lineannotation>
<lineannotation>&lt;!-- map of listeners and their associated topics (channels or/and patterns) --&gt;</lineannotation>
&lt;map&gt;
<emphasis role="bold">&lt;entry key-ref="messageListener"&gt;</emphasis>
&lt;bean class="org.springframework.data.keyvalue.redis.listener.ChannelTopic">

View File

@@ -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;

View File

@@ -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;

View File

@@ -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>

View File

@@ -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"/>