博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring ehcache jms activemq 分布式实现方案
阅读量:2022 次
发布时间:2019-04-28

本文共 2947 字,大约阅读时间需要 9 分钟。

本文章来自国外一个博客,亲测可用,下面粘贴过来的是核心配置。

访问地址:
EHCACHE: It is widely used type of cache.

Replication: If you are using mulitple application server and you need to have same copy of cache at every application server node, then you can use EHCAHE Replication.

I am going to demostrate how EHCACHE replication achieved with Java Message Service in Spring Web Application.

We have choice of using Open MQ and Active MQ. These are open source message queues. I am using Active MQ.

Configuration:

A)Active MQ Setup

  1. You need to download Active MQ server from this link.

I have used -apache-activemq-4.1.0-incubator

2.Extract it.

3.go to follwing path-

—\apache-activemq-4.1.0-incubator\bin

run activemq.bat

ActiveMQ’s default port is 61616.

B)Spring Web App Configuration

3.Spring-context.xml

–We have to create bean -cacheManager, and set configuration file location in property.

  1. ehcache.xml- This fiile actual configuration for Ehcache

5.TestActiveMQInitialContextFactory.java

We have specified

initialContextFactoryName=com.arceler.ehcache.TestActiveMQInitialContextFactory

So we have give following file.

import java.net.URISyntaxException;import java.util.Hashtable;import java.util.Map;import java.util.concurrent.ConcurrentHashMap;import javax.naming.Context;import javax.naming.NamingException;import net.sf.ehcache.distribution.jms.JMSUtil;import org.apache.activemq.jndi.ActiveMQInitialContextFactory;public class TestActiveMQInitialContextFactory extends ActiveMQInitialContextFactory {
/*** Creates an initial context with* {@inheritDoc}*/@Override@SuppressWarnings("unchecked")public Context getInitialContext(Hashtable environment) throws NamingException {Map
data = new ConcurrentHashMap
();String replicationTopicConnectionFactoryBindingName = (String)environment.get(JMSUtil.TOPIC_CONNECTION_FACTORY_BINDING_NAME);if(replicationTopicConnectionFactoryBindingName!=null){try {data.put(replicationTopicConnectionFactoryBindingName, createConnectionFactory(environment));} catch (URISyntaxException e) {throw new NamingException("Error initialisating TopicConnectionFactory with message " + e.getMessage());}}String getQueueConnectionfactoryBindingName = (String)environment.get(JMSUtil.GET_QUEUE_CONNECTION_FACTORY_BINDING_NAME);try {data.put(getQueueConnectionfactoryBindingName, createConnectionFactory(environment));} catch (URISyntaxException e) {throw new NamingException("Error initialisating TopicConnectionFactory with message " + e.getMessage());}String replicationTopicBindingName = (String)environment.get(JMSUtil.REPLICATION_TOPIC_BINDING_NAME);String getQueueBindingName = (String)environment.get(JMSUtil.GET_QUEUE_BINDING_NAME);if(replicationTopicBindingName!=null){data.put(replicationTopicBindingName, createTopic(replicationTopicBindingName));}data.put(getQueueBindingName, createQueue(getQueueBindingName));return createContext(environment, data);}}

转载地址:http://cdgxf.baihongyu.com/

你可能感兴趣的文章
Linux内核开发六:多线程编程和线程安全
查看>>
JavaSE:Java多线程并发和线程同步
查看>>
Java学习资料
查看>>
模板方法模式
查看>>
第十讲、Jmeter之关联
查看>>
Nginx+Tomcat实现动静分离
查看>>
如何防御DDOS等流量攻击
查看>>
Xcode编译生成ipa文件(因为两种证书所以打两个ipa)
查看>>
Mock测试
查看>>
Cookie和session
查看>>
Elasticsearch数据库
查看>>
redis课件总结.
查看>>
Memcache服务
查看>>
Junit单元测试
查看>>
testNG单元测试
查看>>
fiddler抓包
查看>>
Charles抓包
查看>>
C【语言】计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值。
查看>>
计算二元函数
查看>>
5位运动员参加了10米台跳水比赛
查看>>