Spring Integration 配置

<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-jpa="http://www.springframework.org/schema/integration/jpa"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.2.xsd
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.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/integration/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa-2.2.xsd
"> <int-jpa:inbound-channel-adapter
auto-startup="true" entity-manager="em"
send-timeout="60000" channel="process.channel"
expect-single-result="true"
jpa-query="SELECT sysdate FROM dual">
<int:poller fixed-delay="60000" />
</int-jpa:inbound-channel-adapter> <int:channel id="process.channel">
<int:queue capacity="1"/>
</int:channel> <int:chain input-channel="process.channel"> <int-jpa:retrieving-outbound-gateway entity-manager="em" jpa-query="SELECT sp FROM SmsMessage sp Where sp.tatus is null order by sp.requestOn,sp.id"/> <int:splitter ref="process.processSplitter" method="split"/> <int:service-activator ref="process.smsSenderService"
method="send" /> <int:poller fixed-delay="5000" receive-timeout="-1"/>
</int:chain> <bean id="process.smsSenderService" class="com.yd.core.service.SmsSenderService" /> <bean id="process.processSplitter" class="com.yd.core.service.PaymentProcessSplitter" />
</beans>

Job Worker

import org.springframework.context.ApplicationContext;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.support.MessageBuilder; public class JobWorker implements Runnable { private static final int DEFAULT_WAIT_TIME = 3000; @Override
public void run() {
while (true) {
try {
LoggerUtil.getJobLogger().info("JobWorker, Ready for take job run request."); JobRunnerRequest jobRequest = JobManagerService.getJobManager().takeRequest();
while (jobRequest == null) {
LoggerUtil.getJobLogger().warn("JobWorker, jobRequest is null, will try to get the job requet again.");
Thread.sleep(DEFAULT_WAIT_TIME);
jobRequest = JobManagerService.getJobManager().takeRequest();
} LoggerUtil.getJobLogger().info("JobWorker, Received a job run request."); MessageChannel channel = findChannel(jobRequest.getJobChannelId());
if (channel != null) {
channel.send(MessageBuilder.withPayload(jobRequest.getJobMessagePayload()).build());
LoggerUtil.getJobLogger().info("JobWorker, Completed to sned message to job channel");
}
}
catch (Exception ex) {
LoggerUtil.getJobLogger().warn("JobWorker, Completed to sned message to job channel");
}
}
} private MessageChannel findChannel(String jobChannelId) {
ApplicationContext context = ApplicationContextProvider.getContext();
if (context == null) {
LoggerUtil.getJobLogger().error(String.format("JobWorker, Cannot get the application context, to startup job %s", jobChannelId));
return null;
} Object channel = context.getBean(jobChannelId);
if (channel instanceof MessageChannel) {
return (MessageChannel) channel;
}
else {
LoggerUtil.getJobLogger().error(String.format("JobWorker, Cannot get the message bean, to startup job %s", jobChannelId));
return null;
}
}
}

JobManagerService

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue; public final class JobManagerService {
private BlockingQueue<JobRunnerRequest> jobRequestQueue = new LinkedBlockingQueue<JobRunnerRequest>();
private static volatile JobManagerService jobManagerInstnce;
private static Object objSyncLocker = new Object(); private JobManagerService() {
} private void startupWorker() {
new Thread(new JobWorker()).start();
} public static JobManagerService getJobManager() {
if (jobManagerInstnce == null) {
synchronized (objSyncLocker) {
if (jobManagerInstnce == null) {
jobManagerInstnce = new JobManagerService();
jobManagerInstnce.startupWorker();
}
}
}
return jobManagerInstnce;
} public void addRequest(JobRunnerRequest request) {
try {
jobRequestQueue.put(request);
}
catch (InterruptedException e) {
LoggerUtil.getJobLogger().warn(e.getMessage(), e);
}
} public JobRunnerRequest takeRequest() {
try {
return jobRequestQueue.take();
}
catch (InterruptedException e) {
LoggerUtil.getJobLogger().warn(e.getMessage(), e);
return null;
}
}
}

ApplicatonContextProvider

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; public class ApplicationContextProvider implements ApplicationContextAware { private static volatile ApplicationContext ctx; public static ApplicationContext getContext() {
return ctx;
} private static synchronized void setContext(ApplicationContext applicationContext) {
ctx = applicationContext;
} @Override
public void setApplicationContext(ApplicationContext applicationContext){
setContext(applicationContext);
}
}

Spring Integration - 自动轮询发送手机短信的更多相关文章

  1. SNF开发平台WinForm之十二-发送手机短信功能调用-金笛-SNF快速开发平台3.3-Spring.Net.Framework

    1.调用前组装参数 2.调用发送信息服务脚本   .调用前组装参数: BaseSendTaskEntity entity = new BaseSendTaskEntity(); entity.Mess ...

  2. 利用java实现的一个发送手机短信的小例子

    今天闲来无事,在微博上看到一个关于用java实现的一个发送手机短信的程序,看了看,写的不太相信,闲的没事,把他整理下来,以后可能用得着 JAVA发送手机短信,流传有几种方法:(1)使用webservi ...

  3. C#简单实现发送手机短信

    偶然想起,像编写一个从电脑向手机发送短信的程序,从网上查找到有三种方式:(1)使用webservice接口发送手机短信,这个可以使用sina提供的webservice进行发送,但是需要进行注册;(2) ...

  4. JAVA发送手机短信

    <p><span>JAVA发送手机短信,流传有几种方法:(1)使用webservice接口发送手机短信,这个可以使用sina提供的webservice进行发送,但是需要进行注册 ...

  5. 装饰者模式的学习(c#) EF SaveChanges() 报错(转载) C# 四舍五入 保留两位小数(转载) DataGridView样式生成器使用说明 MSSQL如何将查询结果拼接成字符串 快递查询 C# 通过smtp直接发送邮件 C# 带参访问接口,WebClient方式 C# 发送手机短信 文件 日志 写入 与读取

    装饰者模式的学习(c#) 案例转自https://www.cnblogs.com/stonefeng/p/5679638.html //主体基类 using System;using System.C ...

  6. 用Java通过串口发送手机短信

    用Java通过串口发短信其实很简单,因为有现成的类库供我们使用.有底层的类库,也有封装好一点的类库,下面我介绍一下在 Win32 平台下发送短信的方法. 如果你想用更底层的类库开发功能更强大的应用程序 ...

  7. 四:java调接口实现发送手机短信验证码功能

    1.点击获取验证码之前的样式: 2.输入正确的手机号后点击获取验证码之后的样式: 3.如果手机号已经被注册的样式: 4.如果一个手机号一天发送超过3次就提示不能发送: 二:前台的注册页面的代码:reg ...

  8. yii2验证密码->手机号码短信发送>手机短信发送频繁问题

    <?php namespace frontend\models; use Yii; use yii\base\Model; class ChangeMobileSendRequestForm e ...

  9. Java调用WebService接口实现发送手机短信验证码功能,java 手机验证码,WebService接口调用

    近来由于项目需要,需要用到手机短信验证码的功能,其中最主要的是用到了第三方提供的短信平台接口WebService客户端接口,下面我把我在项目中用到的记录一下,以便给大家提供个思路,由于本人的文采有限, ...

随机推荐

  1. September 16th 2016 Week 38th Friday

    All the treasures of the earth would not bring back one lost moment. 机会失去不再来,千贯万贯难赎回. Cherish your h ...

  2. nohup命令

    nohup就是不挂起的意思( n ohang up). .nohup command 或者 nohup command & 这之间的差别是带&的命令行,即使terminal(终端)关闭 ...

  3. 晨跑(bzoj 1877)

    Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十 ...

  4. SQLServer基本操作

    SQL 全名是结构化查询语言(Structured Query Language),是关系数据库管理系统的标准语言 1.分离数据库:将当前数据库文件和数据库引擎的关系断开,没有任何关系了,这样就可以随 ...

  5. 原始套接字SOCK_RAW

    原始套接字SOCK_RAW 实际上,我们常用的网络编程都是在应用层的报文的收发操作,也就是大多数程序员接触到的流式套接字(SOCK_STREAM)和数据包式套接字(SOCK_DGRAM).而这些数据包 ...

  6. 根据复选框checkbox的选中状态来打开或关闭隐藏层

    HTML:  <input type="checkbox" id="check-expert"> <div id="expert&q ...

  7. 使用HttpWebRequest发送自定义POST请求

    平时用浏览器看网页的时候,点击一下submit按钮的时候其实就是给服务器发送了一个POST请求.但是如何在自己的C#程序里面实现类似的功能呢?本文给出了一个简单的范例,可以实现类似的和web serv ...

  8. Android画面显示原理

    转自: http://blog.csdn.net/luoshengyang/article/details/7691321/ http://blog.chinaunix.net/uid-1675954 ...

  9. HTML5学习之拖放(十)

    l元素可以用于拖拽必须设置draggable="true"属性,img和a标签除外,她们两个默认就可以被拖拽 想做拖拽处理,就需要在Dom元素上监听拖放的事件:dragstart, ...

  10. Delphi多线程开发注意事项

    Q1: 多线程中需避免多个线程同时向全局变量进行写入操作,导致访问冲突问题. A1:  可以通过使用加锁机制(比如:临界区.互斥.信号量)解决此问题. Q2:多线程中对于结构体和CLASS类型的全局变 ...