<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd"
xmlns:context="http://www.springframework.org/schema/context" xmlns:int="http://www.springframework.org/schema/integration" xmlns:task="http://www.springframework.org/schema/task"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp">
<int:poller default="true" max-messages-per-poll="10" cron="*/10 * * * * *" />
<task:executor id="taskExecutor" pool-size="20" queue-capacity="20" />
<int:publish-subscribe-channel id="eventPublishChannel" />
<int:publish-subscribe-channel id="asyncEventPublishChannel" task-executor="taskExecutor" />
<int:channel id="ftpChannel">
<!-- <int:queue capacity="25" /> -->
</int:channel>
<bean id="ftpSessionFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="${sudoor.ftp.host}" />
<property name="port" value="${sudoor.ftp.port}" />
<property name="username" value="${sudoor.ftp.username}" />
<property name="password" value="${sudoor.ftp.password}" />
<property name="clientMode" value="${sudoor.ftp.clientMode}" />
<property name="fileType" value="${sudoor.ftp.fileType}" />
<property name="bufferSize" value="${sudoor.ftp.bufferSize}" />
</bean>
<int-ftp:outbound-channel-adapter id="ftpOutbound" channel="ftpChannel" session-factory="ftpSessionFactory" charset="UTF-8"
remote-file-separator="/" auto-create-directory="true" remote-directory="${sudoor.ftp.directory}" mode="REPLACE" />
</beans>
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.annotation.MessagingGateway;
@MessagingGateway
public interface AsyncEventMessageGateway {
@Gateway(requestChannel = "asyncEventPublishChannel")
public void publishEvent(Object event);
}
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator;
@MessageEndpoint
public class DefaultEventServiceActivator {
final Logger logger = LoggerFactory.getLogger(DefaultEventServiceActivator.class);
@ServiceActivator(inputChannel = "eventPublishChannel")
public void handle(Object event) throws Exception {
logger.debug("Get Event: {} @ {}", event, new Date());
}
@ServiceActivator(inputChannel = "asyncEventPublishChannel")
public void handleAsyncEvent(Object event) throws Exception {
logger.debug("Get Asnyc Event: {} @ {}", event, new Date());
}
}
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.annotation.MessagingGateway;
@MessagingGateway
public interface EventMessageGateway {
@Gateway(requestChannel = "eventPublishChannel")
public void publishEvent(Object event);
}
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.annotation.MessagingGateway;
@MessagingGateway
public interface FtpMessageGateway {
@Gateway(requestChannel = "ftpChannel")
public void sendFtpMessage(Object event);
}
@MessageEndpoint
public class RegisterManagerActivator {
private static Logger logger = LoggerFactory.getLogger(RegisterManagerActivator.class);
//private EventMessageGateway eventMessageGateway;
@Autowired
private AsyncEventMessageGateway asyncEventMessageGateway;//异步
@ServiceActivator(inputChannel = "asyncEventPublishChannel")
public void handle(Object event) throws Exception {
}
}
@Component
public class SignUtils{
@Autowired
private AsyncEventMessageGateway asyncEventMessageGateway;//异步
public void addResponseChinapnrLogEventPublish(String responseType,String responseCode,String responseKey
,String responseDescription){
ResponseLog responseLog = new ResponseLog();
responseLog.setResponseType(responseType);
responseLog.setResponseCode(responseCode);
responseLog.setResponseKey(responseKey);
responseLog.setResponseDescription(responseDescription);
responseLog.setResponseDate(new Date());
asyncEventMessageGateway.publishEvent(responseLog);
}
}