distributed-local-caching:
存在的原因
在軟件開發行業,數據的存儲,一般分爲持久化(mysql,postgresql,elasticsearch,hbase,mongo),分佈式緩存(redis,Memcached),以及本地緩存(guava代表的)。而本地緩存,是講數據存儲在每臺服務器的內存中,這樣常常涉及到數據的更新的問題。而分佈式本地緩存就是來解決這個問題
實現原理
note:
* 生產者可能是消費者
* 消息是通過Fanout exchange實現廣播的
* 數據的存儲通過guava的cache實現的
例子
生產者:
“` java
@Before
public void initProductMessageClient() throws IOException{
LocalCacheClientConfiguration configuration = new LocalCacheClientConfiguration();
configuration.setAddress("128.0.0.1:5672");
configuration.setvHost("/dev");
configuration.setUser("user");
configuration.setPwd("pwd");
productMessageClient = new ProductMessageClient(configuration);
}
@Test
public void testSendRemoveDataMessage() throws IOException {
while (true) {
productMessageClient.sendRemoveDataMessage("111");
}
}
“`
消費者:
“` java
@Before
public void initProductMessageClient() throws IOException {
LocalCacheClientConfiguration configuration = new LocalCacheClientConfiguration();
configuration.setAddress("128.0.0.1:5672");
configuration.setvHost("/dev");
configuration.setUser("user");
configuration.setPwd("pwd");
configuration.setQueueName("lc-queue");
configuration.setQosCount(5);
consumerMessageClient = new ConsumerMessageClient(new LocalCacheConfiguration(), configuration);
}
@Test
public void testConsumer() throws IOException {
consumerMessageClient.consumer();
try {
Thread.sleep(10000000);
} catch (Exception e) {
e.printStackTrace();
}
}
“`
github地址
項目地址
有錯的地方,歡迎大家指出來。