问题:
移动开通一个短信网关供系统发送短信,后来随着业务增加、以及外系统短信接口接入,导致本系统短信模块处理量急剧增加,每秒发送短信50-80条,每逢访问高峰期,导致短信网关堵塞。
其次是短信模块部署在应用系统现网环境中,应用系统与短信模块性能上相互影响,不稳定。
方案:
由于短信模块直接与短信网关打交道,而应用系统、外系统想发送短息直接与短信模块打交道
可单独部署一个短信服务域,本系统、外系统直接访问短信服务域公布的接口访问即可。
通过在短信模块与短信网关中间建立一个缓冲池(JMS)缓冲短消息
实施:
步骤一、
服务域的部署(省略)
步骤二、
配置JMS(省略)
步骤三、
改造原先短信发送的代码
JMS连接初始化:
private QueueConnection connection;
private QueueSession session;
private QueueSender sender;
public void initialize() throws Exception
{
if (log.isInfoEnabled()) {
log.info("Starting JMS Queue Sender Service...");
}
try
{
InitialContext jndi = getInitialContext("t3://host:port");
QueueConnectionFactory factory = (QueueConnectionFactory)jndi.lookup("QueueConnectionFactory");
connection = factory.createQueueConnection();
session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)jndi.lookup("SMSQueue");
sender = session.createSender(queue);
connection.start();
}
catch(Exception e)
{
throw e;
}
}
//发送短信数据方法
public void sendNotification(Serializable message)
{
try
{
ObjectMessage object = session.createObjectMessage();
object.setObject(message);
sender.send(object);
log.info("Message Sender send object:" + object.getObject());
}
catch(JMSException e)
{
log.error("A problem was encountered when create Object Message", e);
e.printStackTrace();
}
}
步骤四、
短信服务域增加消费JMS消息的监听器
public void initialize() throws Exception
{
if (log.isInfoEnabled()) {
log.info("Starting JMS Queue Receiver Service...");
}
try
{
InitialContext jndi = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory)jndi.lookup("QueueConnectionFactory");
connection = factory.createQueueConnection();
session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)jndi.lookup("SMSQueue");
sender = session.createSender(queue);
connection.start();
QueueReceiver receiver = session.createReceiver(queue);
receiver.setMessageListener(new MessageListener(){
public void onMessage(Message message)
{
try
{
ObjectMessage objectMessage = null;
if (!(message instanceof ObjectMessage)) {
log.error("Cannot handle message of type (class=" + message.getClass().getName() + "). Notification ignored.");
return;
}
objectMessage = (ObjectMessage) message;
//check the message content
if (!(objectMessage.getObject() instanceof MessageEntity)) {
log.error("An unknown cluster notification message received (class=" + objectMessage.getObject().getClass().getName() + "). Notification ignored.");
return;
}
if (log.isDebugEnabled()) {
log.debug(objectMessage.getObject());
}
//实际调用短信网关发送短信的方法
handleNotification(objectMessage.getObject());
} catch (JMSException jmsEx) {
log.error("Cannot handle cluster Notification", jmsEx);
}
}
});
}
catch(Exception e)
{
throw e;
}
}
分享到:
相关推荐
赠送jar包:geronimo-jms_1.1_spec-1.1.1.jar; 赠送原API文档:geronimo-jms_1.1_spec-1.1.1-javadoc.jar; 赠送源代码:geronimo-jms_1.1_spec-1.1.1-sources.jar; 包含翻译后的API文档:geronimo-jms_1.1_...
geronimo-jms_1.1_spec-1.0.jar
赠送jar包:spring-jms-4.3.20.RELEASE.jar 赠送原API文档:spring-jms-4.3.20.RELEASE-javadoc.jar 赠送源代码:spring-jms-4.3.20.RELEASE-sources.jar 包含翻译后的API文档:spring-jms-4.3.20.RELEASE-...
赠送jar包:spring-jms-4.3.20.RELEASE.jar; 赠送原API文档:spring-jms-4.3.20.RELEASE-javadoc.jar; 赠送源代码:spring-jms-4.3.20.RELEASE-sources.jar; 包含翻译后的API文档:spring-jms-4.3.20.RELEASE-...
赠送jar包:spring-jms-4.3.12.RELEASE.jar; 赠送原API文档:spring-jms-4.3.12.RELEASE-javadoc.jar; 赠送源代码:spring-jms-4.3.12.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-jms-4.3.12.RELEASE....
spring-jms-4.0.0.RELEASE.jar spring-jms-4.0.0.RELEASE.jar spring-jms-4.0.0.RELEASE.jar spring-jms-4.0.0.RELEASE.jar
spring-jmsspring-jmsspring-jmsspring-jmsspring-jmsspring-jms
赠送jar包:geronimo-jms_1.1_spec-1.1.1.jar; 赠送原API文档:geronimo-jms_1.1_spec-1.1.1-javadoc.jar; 赠送源代码:geronimo-jms_1.1_spec-1.1.1-sources.jar; 包含翻译后的API文档:geronimo-jms_1.1_...
spring-jms-5.0.4.RELEASE.jar ;spring-jms-5.0.4.RELEASE.jar
spring-jms-3.1.1.RELEASE.jar
包含:groboutils-core-5.jar、fastdfs-client、kaptcha-2.3.2.jar、pinyin4j-2.5.0.jar、proton-jms-0.3.0-fuse-2.jar等
activemq-jms-pool-5.14.4.jar
Atomikos Transactions JMS 是一个专门用于处理分布式事务管理的Java库,主要针对JMS(Java Message Service)环境。这个库被封装在名为"atomikos-transactions-jms.jar"的JAR文件中,通常作为开发人员在构建支持...
spring-jms-4.1.4,Spring提供的JMS工具类,它发送、接收消息
spring-jms-4.1.0.RELEASE.ja
ActiveMQ是Apache提供的开源JMS消息代理,具有高性能、高可用性等特点。配置Spring-JMS与ActiveMQ的集成,主要涉及连接工厂和目的地的配置。 **9. Spring Boot与Spring-JMS** 在Spring Boot项目中,通过添加相关...
赠送jar包:spring-jms-4.3.12.RELEASE.jar; 赠送原API文档:spring-jms-4.3.12.RELEASE-javadoc.jar; 赠送源代码:spring-jms-4.3.12.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-jms-4.3.12.RELEASE....
标签:activemq-jms-pool-5.9.0.jar,activemq,jms,pool,5.9.0,jar包下载,依赖包
标签:activemq-jms-pool-5.9.1.jar,activemq,jms,pool,5.9.1,jar包下载,依赖包
标签:activemq-jms-pool-5.9.1-javadoc.jar,activemq,jms,pool,5.9.1,javadoc,jar包下载,依赖包