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. Smarty模板技术学习(二)

    本文主要包括以下内容 公共文件引入与继承 内容捕捉 变量调剂器 缓存 Smarty过滤器 数据对象.注册对象 与已有项目结合 公共文件引入与继承 可以把许多模板页面都用到的公共页面放到单独文件里边,通 ...

  2. Java中length,length(),size()区别

    length属性:用于获取数组长度. eg: int ar[] = new int{1,2,3} /** * 数组用length属性取得长度 */ int lenAr = ar.length;//此处 ...

  3. C#回顾 - 2.NET的IO:Path、File、FileInfo、Directory、DirectoryInfo、DriveInfo、FileSystemWatcher

        1.管理文件系统 一般而言,应用程序都会有保存数据.检索数据的需求. 1.1 使用 path 类来访问文件路径 [path常用的方法]:http://www.cnblogs.com/tangg ...

  4. ExcelReport第二篇:ExcelReport源码解析

    导航 目   录:基于NPOI的报表引擎——ExcelReport 上一篇:使用ExcelReport导出Excel 下一篇:扩展元素格式化器 概述 针对上一篇随笔收到的反馈,在展开对ExcelRep ...

  5. 在SQL里如何写条件逻辑?

    主要涉及CASE,WHEN之类.. 不同的服务器上实现if...else...是不一样的. 建议用CASE ,WHEN,因为它们是SQL国标呢. mysql> SELECT -> SUM( ...

  6. hdu 1075:What Are You Talking About(字典树,经典题,字典翻译)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  7. eclipse基础及开发插件

    Eclipse:http://www.eclipse.org/downloads/ Compare Package:http://www.eclipse.org/downloads/packages/ ...

  8. js 横幅播放

    js 横幅播放 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  9. PHPCMS V9 栏目列表调用文章点击量及评论数量方法

    很多朋友在用Phpcms做站时,具体需要在列表页.首页调用文章列表调用文章的点击量和评论排行,那么怎么才能做到在Phpcms v9首页.频道页.列表页.推荐位等页面获取文章浏览量和评论统计呢? 原因起 ...

  10. hdu 5289 rmp+二分+枚举后界 or单调队列 ****

    好题~~ 给你n个数和k,求有多少的区间使得区间内部任意两个数的差值小于k,输出符合要求的区间个数,枚举后界~~ 又是一种没见过的方法,太弱了/(ㄒoㄒ)/~~ #include <cstdio ...