INT-2032 migrated 'spring-integration-gemfire' to main branch from sandbox in preparation for 2.1 development

This commit is contained in:
Mark Fisher
2011-08-04 16:16:13 -04:00
parent 2f5bf21e16
commit c35a79a0e9
54 changed files with 2690 additions and 555 deletions

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire;
import com.gemstone.gemfire.cache.EntryEvent;
import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* (this is the CacheLogger class that ships in the Spring-Gemfire samples)
*
* @author Costin Leau
*/
public class TestCacheListenerLogger extends CacheListenerAdapter<Object, Object> {
private static final Log log = LogFactory.getLog(TestCacheListenerLogger.class);
@Override
public void afterCreate(EntryEvent<Object, Object> event) {
log.info("Added " + messageLog(event) + " to the cache");
}
@Override
public void afterDestroy(EntryEvent<Object, Object> event) {
log.info("Removed " + messageLog(event) + " from the cache");
}
@Override
public void afterUpdate(EntryEvent<Object, Object> event) {
log.info("Updated " + messageLog(event) + " in the cache");
}
private String messageLog(EntryEvent<Object, Object> event) {
Object key = event.getKey();
Object value = event.getNewValue();
if (event.getOperation().isUpdate()) {
return "[" + key + "] from [" + event.getOldValue() + "] to [" + event.getNewValue() + "]";
}
return "[" + key + "=" + value + "]";
}
}

View File

@@ -0,0 +1,141 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire.inbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.Region;
/**
* @author Mark Fisher
* @since 2.1
*/
public class CacheListeningMessageProducerTests {
@Test
public void receiveNewValuePayloadForCreateEvent() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
cacheFactoryBean.afterPropertiesSet();
Cache cache = cacheFactoryBean.getObject();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
regionFactoryBean.setName("test.receiveNewValuePayloadForCreateEvent");
regionFactoryBean.setCache(cache);
regionFactoryBean.afterPropertiesSet();
Region<String, String> region = regionFactoryBean.getObject();
QueueChannel channel = new QueueChannel();
CacheListeningMessageProducer producer = new CacheListeningMessageProducer(region);
producer.setPayloadExpression("key + '=' + newValue");
producer.setOutputChannel(channel);
producer.afterPropertiesSet();
producer.start();
assertNull(channel.receive(0));
region.put("x", "abc");
Message<?> message = channel.receive(0);
assertNotNull(message);
assertEquals("x=abc", message.getPayload());
}
@Test
public void receiveNewValuePayloadForUpdateEvent() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
cacheFactoryBean.afterPropertiesSet();
Cache cache = cacheFactoryBean.getObject();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
regionFactoryBean.setName("test.receiveNewValuePayloadForUpdateEvent");
regionFactoryBean.setCache(cache);
regionFactoryBean.afterPropertiesSet();
Region<String, String> region = regionFactoryBean.getObject();
QueueChannel channel = new QueueChannel();
CacheListeningMessageProducer producer = new CacheListeningMessageProducer(region);
producer.setPayloadExpression("newValue");
producer.setOutputChannel(channel);
producer.afterPropertiesSet();
producer.start();
assertNull(channel.receive(0));
region.put("x", "abc");
Message<?> message1 = channel.receive(0);
assertNotNull(message1);
assertEquals("abc", message1.getPayload());
region.put("x", "xyz");
Message<?> message2 = channel.receive(0);
assertNotNull(message2);
assertEquals("xyz", message2.getPayload());
}
@Test
public void receiveOldValuePayloadForDestroyEvent() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
cacheFactoryBean.afterPropertiesSet();
Cache cache = cacheFactoryBean.getObject();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
regionFactoryBean.setName("test.receiveOldValuePayloadForDestroyEvent");
regionFactoryBean.setCache(cache);
regionFactoryBean.afterPropertiesSet();
Region<String, String> region = regionFactoryBean.getObject();
QueueChannel channel = new QueueChannel();
CacheListeningMessageProducer producer = new CacheListeningMessageProducer(region);
producer.setSupportedEventTypes(EventType.DESTROYED);
producer.setPayloadExpression("oldValue");
producer.setOutputChannel(channel);
producer.afterPropertiesSet();
producer.start();
assertNull(channel.receive(0));
region.put("foo", "abc");
assertNull(channel.receive(0));
region.destroy("foo");
Message<?> message2 = channel.receive(0);
assertNotNull(message2);
assertEquals("abc", message2.getPayload());
}
@Test
public void receiveOldValuePayloadForInvalidateEvent() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
cacheFactoryBean.afterPropertiesSet();
Cache cache = cacheFactoryBean.getObject();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
regionFactoryBean.setName("test.receiveOldValuePayloadForDestroyEvent");
regionFactoryBean.setCache(cache);
regionFactoryBean.afterPropertiesSet();
Region<String, String> region = regionFactoryBean.getObject();
QueueChannel channel = new QueueChannel();
CacheListeningMessageProducer producer = new CacheListeningMessageProducer(region);
producer.setSupportedEventTypes(EventType.INVALIDATED);
producer.setPayloadExpression("key + ' was ' + oldValue");
producer.setOutputChannel(channel);
producer.afterPropertiesSet();
producer.start();
assertNull(channel.receive(0));
region.put("foo", "abc");
assertNull(channel.receive(0));
region.invalidate("foo");
Message<?> message2 = channel.receive(0);
assertNotNull(message2);
assertEquals("foo was abc", message2.getPayload());
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire.inbound.cq;
import org.springframework.integration.Message;
import org.springframework.integration.annotation.ServiceActivator;
import com.gemstone.gemfire.cache.query.CqEvent;
public class CqServiceActivator {
@ServiceActivator
public void handleMessage(Message<CqEvent> msg) throws Exception {
CqEvent cqEvent = msg.getPayload();
System.out.println( "Received an event from the continuous query adapter: " +cqEvent );
}
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire.inbound.cq.client;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.gemfire.inbound.cq.CqServiceActivator;
import com.gemstone.gemfire.cache.client.Pool;
import com.gemstone.gemfire.cache.client.PoolManager;
@Configuration
@SuppressWarnings("unused")
public class CqClientConfiguration {
@Value("${region-name}")
private String regionName;
@Value("${host}")
private String host;
@Value("${region-query}")
private String query;
@Value("${port}")
private int port;
@Value("#{cqIn}")
private MessageChannel messageChannel;
@Bean
public CqServiceActivator cqServiceActivator() {
return new CqServiceActivator();
}
/* todo
protected ClientCache buildCache() throws Throwable {
return new ClientCacheFactory().create();
}
@Bean
public ClientCache clientCache() throws Throwable {
return buildCache();
}
@Bean
public Region<?, ?> clientRegion() throws Throwable {
ClientRegionFactory<?, ?> clientRegionFactory = clientCache().createClientRegionFactory(ClientRegionShortcut.PROXY);
return clientRegionFactory.create(this.regionName);
}
*/
@Bean
public Pool pool() throws Throwable {
return this.buildPool(this.host, this.port);
}
/*@Bean
public ContinuousQueryMessageProducer continuousQueryMessageProducer() throws Throwable {
ContinuousQueryMessageProducer continuousQueryMessageProducer
= new ContinuousQueryMessageProducer( this.clientRegion() , this.pool(), this.query);
continuousQueryMessageProducer.setDurable(true);
continuousQueryMessageProducer.setOutputChannel(this.messageChannel);
continuousQueryMessageProducer.setQueryName("pplQuery");
return continuousQueryMessageProducer;
}
*/
/* protected CqQuery registerContinuousQuery(QueryService queryService, String name, String query, boolean durable, CqListener cqListener) throws Throwable {
CqAttributesFactory cqAttributesFactory = new CqAttributesFactory();
cqAttributesFactory.addCqListener(cqListener);
CqAttributes attrs = cqAttributesFactory.create();
CqQuery cqQuery = queryService.newCq(name, query, attrs, durable);
cqQuery.execute();
return cqQuery;
}*/
protected Pool buildPool(String host, int port) throws Throwable {
Pool pool = PoolManager.createFactory()
.addServer(host, port)
.setSubscriptionEnabled(true)
.create(host + "Pool");
return pool;
}
/**
* the continuous query listener attached to the
*/
/*class MyContinuousQueryListener implements CqListener {
public void onEvent(CqEvent cqEvent) {
System.out.println("Received event: " +
new ToStringCreator(cqEvent));
}
public void onError(CqEvent cqEvent) {
}
public void close() {
}
}*/
public static void main(String[] args) throws Exception {
new ClassPathXmlApplicationContext("org/springframework/integration/gemfire/inbound/cq/CqClient-context.xml");
while (true) {
Thread.sleep(1000 * 10);
}
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire.inbound.cq.server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.gemfire.GemfireTemplate;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.server.CacheServer;
@Configuration
@SuppressWarnings("unused")
public class CqServerConfiguration {
@Value("#{c}")
private Cache cache;
@Value("#{r}")
private Region<String, ?> region;
@Value("${region-name}")
private String regionName;
@Value("${host}")
private String host;
@Value("${port}")
private int port;
@Bean
public GemfireTemplate gemfireTemplate() {
return new GemfireTemplate(this.region);
}
@Bean
public CacheServer cacheServer() throws Throwable {
CacheServer cacheServer = this.cache.addCacheServer();
cacheServer.setBindAddress(this.host);
cacheServer.setPort(this.port);
cacheServer.start();
return cacheServer;
}
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"org/springframework/integration/gemfire/inbound/cq/CqServer-context.xml");
applicationContext.registerShutdownHook();
applicationContext.start();
GemfireTemplate gemfireTemplate = applicationContext.getBean(GemfireTemplate.class);
String letters = "abcdefghijk";
while (true) {
Thread.sleep(1000 * 10);
for (char c : letters.toCharArray()) {
gemfireTemplate.put("" + c, "value-" + c);
}
}
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire.outbound;
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.integration.Message;
import org.springframework.integration.support.MessageBuilder;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.Region;
/**
* @author Mark Fisher
* @since 2.1
*/
public class CacheWritingMessageHandlerTests {
@Test
public void mapPayloadWritesToCache() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
cacheFactoryBean.afterPropertiesSet();
Cache cache = cacheFactoryBean.getObject();
RegionFactoryBean<String, String> regionFactoryBean = new RegionFactoryBean<String, String>();
regionFactoryBean.setName("test.mapPayloadWritesToCache");
regionFactoryBean.setCache(cache);
regionFactoryBean.afterPropertiesSet();
Region<String, String> region = regionFactoryBean.getObject();
assertEquals(0, region.size());
CacheWritingMessageHandler handler = new CacheWritingMessageHandler(region);
Map<String, String> map = new HashMap<String, String>();
map.put("foo", "bar");
Message<?> message = MessageBuilder.withPayload(map).build();
handler.handleMessage(message);
assertEquals(1, region.size());
assertEquals("bar", region.get("foo"));
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire.store;
import static org.junit.Assert.assertEquals;
import java.util.UUID;
import org.junit.Test;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.integration.Message;
import org.springframework.integration.store.MessageStore;
import org.springframework.integration.support.MessageBuilder;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.Region;
/**
* @author Mark Fisher
* @since 2.1
*/
public class GemfireMessageStoreTests {
@Test
public void addAndGetMessage() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
cacheFactoryBean.afterPropertiesSet();
Cache cache = cacheFactoryBean.getObject();
RegionFactoryBean<UUID, Message<?>> regionFactoryBean = new RegionFactoryBean<UUID, Message<?>>();
regionFactoryBean.setName("test.addAndGetMessage");
regionFactoryBean.setCache(cache);
regionFactoryBean.afterPropertiesSet();
Region<UUID, Message<?>> region = regionFactoryBean.getObject();
MessageStore store = new GemfireMessageStore(region);
Message<?> message = MessageBuilder.withPayload("test").build();
store.addMessage(message);
Message<?> retrieved = store.getMessage(message.getHeaders().getId());
assertEquals(message, retrieved);
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire.store.messagegroupstore;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.Message;
import org.springframework.integration.aggregator.CorrelationStrategy;
import org.springframework.integration.aggregator.HeaderAttributeCorrelationStrategy;
import org.springframework.integration.aggregator.ReleaseStrategy;
import org.springframework.integration.aggregator.SequenceSizeReleaseStrategy;
import org.springframework.integration.gemfire.store.KeyValueMessageGroup;
import org.springframework.integration.gemfire.store.KeyValueMessageGroupStore;
/**
* Our aggregator needs a {@link org.springframework.integration.gemfire.store.KeyValueMessageGroupStore}.
* This handles configuration of the ancillary objects.
*
* @author Josh Long
* @since 2.1
*/
@Configuration
public class GemfireMessageStoreConfiguration {
@Value("${correlation-header}")
private String correlationHeader;
@Value("#{unmarkedRegion}")
private Map<String, Message<?>> unmarked;
@Value("#{markedRegion}")
private Map<String, Message<?>> marked;
@Value("#{messageGroupRegion}")
private Map<Object, KeyValueMessageGroup> messageGroupRegion;
@Bean
public ReleaseStrategy releaseStrategy() {
return new SequenceSizeReleaseStrategy(false);
}
@Bean
public CorrelationStrategy correlationStrategy() {
return new HeaderAttributeCorrelationStrategy(this.correlationHeader);
}
@Bean
public KeyValueMessageGroupStore gemfireMessageGroupStore() {
return new KeyValueMessageGroupStore(this.messageGroupRegion, this.marked , this.unmarked );
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire.store.messagegroupstore;
import java.util.Arrays;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Simple example demonstrating the use of a {@link org.springframework.integration.gemfire.store.KeyValueMessageGroupStore}.
*
* @author Josh Long
* @since 2.1
*/
public class Main {
public static void main(String[] args) throws Throwable {
ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
"/org/springframework/integration/gemfire/store/messagegroupstore/GemfireMessageStore-context.xml");
Producer producer = classPathXmlApplicationContext.getBean(Producer.class);
for(int i =0 ; i < 10 ; i++ ) {
producer.sendManyMessages(i, Arrays.asList("1,2,3,4,5".split(",")));
}
Thread.sleep( 1000 * 10 );
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire.store.messagegroupstore;
import java.util.Collection;
import org.springframework.integration.Message;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
/**
* @author Josh Long
* @since 2.1
*/
@Component
public class MessageGroupStoreActivator {
@ServiceActivator
public void activate(Message<Collection<Object>> msg) throws Throwable {
Collection<Object> payloads = msg.getPayload();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 100; i++) {
buffer.append("-");
}
System.out.println(buffer.toString());
System.out.println(StringUtils.collectionToCommaDelimitedString(payloads));
}
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gemfire.store.messagegroupstore;
import java.util.Collection;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
/**
* Simple endpoint that we can use to send in a lot of test messages.
*
* @author Josh Long
* @since 2.1
*/
@Component
public class Producer {
private MessagingTemplate messagingTemplate = new MessagingTemplate();
@Value("#{i}")
private MessageChannel messageChannel;
@Value("${correlation-header}")
private String correlationHeader ;
@PostConstruct
public void start() throws Throwable {
this.messagingTemplate.setDefaultChannel(this.messageChannel);
}
/**
* @param lines
* @throws Throwable
*/
public void sendManyMessages(int correlationValue, Collection<String> lines) throws Throwable {
Assert.notNull( lines, "the collection must be non-null");
Assert.notEmpty( lines, "the collection must not be empty");
int ctr = 0;
int size = lines.size() ;
for (String l : lines) {
Message<?> msg = MessageBuilder.withPayload(l)
.setCorrelationId( this.correlationHeader)
.setHeader(this.correlationHeader , correlationValue)
.setSequenceNumber(++ctr)
.setSequenceSize(size)
.build();
this.messagingTemplate.send(msg);
}
}
}

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:gfe="http://www.springframework.org/schema/gemfire" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="org.springframework.integration.gemfire.inbound.cq.client"/>
<context:property-placeholder location="org/springframework/integration/gemfire/inbound/cq/common.properties"/>
<!--<util:properties id="props" location="org/springframework/integration/gemfire/inbound/cq/gfe-cache.properties"/>-->
<int:channel id="cqIn"/>
<int:service-activator input-channel="cqIn" ref="cqServiceActivator"/>
</beans>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:gfe="http://www.springframework.org/schema/gemfire" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- infrastrcture-->
<context:component-scan base-package="org.springframework.integration.gemfire.inbound.cq.server"/>
<context:property-placeholder location="org/springframework/integration/gemfire/inbound/cq/common.properties"/>
<!-- setup the cache-->
<util:properties id="props" location="org/springframework/integration/gemfire/inbound/cq/gfe-cache.properties"/>
<gfe:cache properties-ref="props" id="c"/>
<!-- tx manager-->
<gfe:transaction-manager cache-ref="c"/>
<!-- region -->
<gfe:replicated-region id="r" name="${region-name}" cache-ref="c" />
</beans>

View File

@@ -0,0 +1,5 @@
host=127.0.0.1
port=55221
region-name=people
region-query=select * from /people
correlation-header=time

View File

@@ -0,0 +1,3 @@
log-level=warning
name=Spring Integration GemFire World
bind-address=127.0.0.1

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:gfe="http://www.springframework.org/schema/gemfire" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="org/springframework/integration/gemfire/inbound/cq/common.properties"/>
<context:component-scan base-package="org.springframework.integration.gemfire.store.messagegroupstore"/>
<int:channel id="i"/>
<int:aggregator release-strategy="releaseStrategy" correlation-strategy="correlationStrategy" message-store="gemfireMessageGroupStore" input-channel="i" output-channel="o" />
<int:channel id="o"/>
<int:service-activator input-channel="o" ref="messageGroupStoreActivator" />
<util:properties id="props" location="org/springframework/integration/gemfire/inbound/cq/gfe-cache.properties"/>
<gfe:cache properties-ref="props" id="c"/>
<gfe:transaction-manager cache-ref="c"/>
<gfe:replicated-region id="unmarkedRegion" cache-ref="c"/>
<gfe:replicated-region id="markedRegion" cache-ref="c"/>
<gfe:replicated-region id="messageGroupRegion" cache-ref="c"/>
</beans>