Updated demo to use @Polled

This commit is contained in:
Mark Fisher
2007-12-14 19:40:58 +00:00
parent ff97fa572b
commit c16ab8fa63
5 changed files with 10 additions and 40 deletions

View File

@@ -23,7 +23,7 @@ import org.springframework.integration.endpoint.annotation.Subscriber;
*/
public class Logger {
//@Subscriber(channel="quotes")
@Subscriber(channel="quotes")
public void log(Object o) {
System.out.println(o);
}

View File

@@ -20,17 +20,19 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Random;
import org.springframework.integration.aop.Publisher;
import org.springframework.integration.endpoint.annotation.MessageEndpoint;
import org.springframework.integration.endpoint.annotation.Polled;
/**
* @author Mark Fisher
*/
public class StubQuoteService implements QuoteService {
@MessageEndpoint(defaultOutput="quotes")
public class QuotePublisher {
@Publisher(channel="quotes")
public Quote lookup(String ticker) {
@Polled(period=300)
public Quote getQuote() {
BigDecimal price = new BigDecimal(new Random().nextDouble() * 100);
return new Quote(ticker, price.setScale(2, RoundingMode.HALF_EVEN));
return new Quote("SOA", price.setScale(2, RoundingMode.HALF_EVEN));
}
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright 2002-2007 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.samples;
/**
* @author Mark Fisher
*/
public interface QuoteService {
Quote lookup(String ticker);
}

View File

@@ -27,8 +27,6 @@ public class StockQuoteDemo {
public static void main(String[] args) throws Exception {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("stockQuoteDemo.xml", StockQuoteDemo.class);
context.start();
QuoteService service = (QuoteService) context.getBean("quoteService");
service.lookup("SOA");
Thread.sleep(1000);
System.in.read();
}
}

View File

@@ -13,11 +13,7 @@
<channel id="quotes"/>
<endpoint input-channel="quotes" handler="logger" handler-method="log">
<consumer period="1000"/>
</endpoint>
<beans:bean id="quoteService" class="org.springframework.integration.samples.StubQuoteService"/>
<beans:bean id="quotePublisher" class="org.springframework.integration.samples.QuotePublisher"/>
<beans:bean id="logger" class="org.springframework.integration.samples.Logger"/>