메시징 및 스트림

오늘날 많은 서버 애플리케이션은 다른 애플리케이션과의 작업을 조정하고 비동기 방식으로 메시지와 데이터를 공유해야 합니다. 그리고 이는 종종 트랜잭션이 많은 환경에서 수행됩니다. 높은 트랜잭션 환경의 경우, NCache 이들에게 이상적인 후보입니다 비동기 이벤트 중심 통신.

NCache 다음을 포함하여 이러한 애플리케이션의 요구 사항을 충족할 수 있는 풍부한 메시징 및 스트림 기능 세트를 제공합니다. 게시/구독 메시징, 연속 쿼리, 아이템 레벨 이벤트캐시 레벨 이벤트. 각각은 아래에 설명되어 있습니다.

Pub/Sub 메시징, 연속 쿼리 및 이벤트
 

게시/구독 메시징

NCache 강력한 제공 게시/구독 메시징 게시자 애플리케이션이 구독자가 누구인지 알지 못한 채 메시지를 보낼 수 있는 애플리케이션용 플랫폼입니다. 메시지는 다음과 같이 분류될 수 있습니다. 이상의 주제 그런 다음 구독자는 특정 주제를 구독하고 이러한 메시지를 비동기적으로 받을 수 있습니다.

  • - 제작사 : 여러 구독자가 사용할 메시지를 게시합니다. 게시자는 구독자가 누구인지, 얼마나 많은지 모릅니다.
  • - 구독자: 특정 주제에 대한 메시지를 수신하도록 자신을 등록합니다. 구독자는 게시자가 누구인지, 다른 구독자가 몇 명인지 알지 못합니다.
  • - 주제 : 모든 메시지는 주제에 대해 게시되고 수신됩니다. 게시자는 이에 대한 메시지를 게시하고 구독자는 해당 메시지를 받습니다. 여러 주제를 가질 수 있습니다 NCache.
  • - 요청사항: 이는 게시자가 보내고 구독자가 소비하는 실제 메시지입니다.

당신은 쉽게 할 수 사용 NCache 분산 애플리케이션을 위한 Pub/Sub 메시징 Pub/Sub 메시징의 구성요소와 작동 방식을 이해한 후

Pub/Sub 메시징 NCache

아래는 에 대한 소스 코드 예입니다. 게시자가 메시지를 게시하는 방법 주제로 이동한 다음 구독자가 주제를 구독합니다..

ITopic topic = _cache.MessagingService.CreateTopic(topicName)

// Creating new message containing a “payload” 
var message = new Message(payload);

// Set the expiration TimeSpan of the message
message.ExpirationTime = TimeSpan.FromSeconds(5000);

// Publishing the above created message.
topic.Publish(message, DeliveryOption.All, true);

// Get the already created topic to subscribe to it
ITopic orderTopic = cache.MessagingService.GetTopic(topic);

// Create and register subscribers for the topic created
// MessageRecieved callback is registered
orderTopic.CreateSubscription(MessageReceived);
String topicName = "orderUpdates";
Topic topic = cache.getMessagingService().createTopic(topicName);

// Creating new message containing a “payload”
Customer payload = new Customer("David Jones", "XYZCompany");
var message = new Message(payload);

// Set the expiration TimeSpan of the message
message.setExpirationTime(TimeSpan.FromSeconds(5000));

// Publishing the above created message.
topic.publish(message, DeliveryOption.All, true);

// Get the already created topic to subscribe to it
Topic orderTopic = cache.getMessagingService().getTopic(topicName);

// Create and register subscribers for the topic created
orderTopic.createSubscription(new MessageReceivedListener() {
    @Override
     public void onMessageReceived(Object sender, MessageEventArgs args) {
// message received
     }
});
 

연속 쿼리(CQ)

연속 쿼리 의 강력한 특징이다 NCache 이를 통해 SQL과 유사한 쿼리를 기반으로 분산 캐시의 "데이터 세트"에 대한 변경 사항을 모니터링할 수 있습니다. 캐시에 대해 SQL과 유사한 기준을 사용하여 연속 쿼리(CQ)를 생성하고 이를 NCache. NCache 그때 이 "데이터 세트"에 대한 변경 사항을 모니터링하기 시작합니다. 다음을 포함하는 캐시에:

  • - 추가 : CQ 기준과 일치하는 항목이 캐시에 추가되면 클라이언트는 이 개체와 함께 알림을 받습니다.
  • - 업데이트 : CQ 기준과 일치하는 항목이 캐시에서 업데이트되면 클라이언트는 이 개체와 함께 알림을 받습니다.
  • - 풀다: CQ 기준과 일치하는 항목이 캐시에서 제거되면 클라이언트는 이 개체와 함께 알림을 받습니다.

다음은 특정 기준으로 연속 쿼리를 만들고 서버에 등록하는 방법입니다.

// Query for required operation
string query = "SELECT $VALUE$ FROM FQN.Customer WHERE Country = ?";

var queryCommand = new QueryCommand(query);
queryCommand.Parameters.Add("Country", "USA");

// Create Continuous Query
var cQuery = new ContinuousQuery(queryCommand);

// Register to be notified when a qualified item is added to the cache
cQuery.RegisterNotification(new QueryDataNotificationCallback(QueryItemCallBack), EventType.ItemAdded, EventDataFilter.None);

// Register continuousQuery on server 
cache.MessagingService.RegisterCQ(cQuery);
String cacheName = "demoCache";

// Initialize an instance of the cache to begin performing operations:
Cache cache = CacheManager.getCache(cacheName);

// Query for required operation
String query = "SELECT $VALUE$ FROM com.alachisoft.ncache.sample.Customer WHERE country = ?";

var queryCommand = new QueryCommand(query);
queryCommand.getParameters().put("Country", "USA");

// Create Continuous Query
var cQuery = new ContinuousQuery(queryCommand);

// Register to be notified when a qualified item is added to the cache
cQuery.addDataModificationListener(new QueryDataModificationListener() {
	@Override
	public void onQueryDataModified(String key, CQEventArg args) {
		switch (args.getEventType())
		{
			case ItemAdded:
				// 'key' has been added to the cache
				break;
		}
	}
  }, EnumSet.allOf(EventType.class), EventDataFilter.None);

// Register continuousQuery on server
cache.getMessagingService().registerCQ(cQuery);

자세한 내용은 다음을 참조하십시오. 캐시 문서에서 연속 쿼리를 사용하는 방법.

 

이벤트 알림

클라이언트는 다음으로 등록합니다. NCache 수신 이벤트 알림 그들은 콜백 기능을 제공함으로써 관심을 갖고 있습니다. NCache 이벤트와 함께 반환되는 정보의 양을 지정하는 데 사용되는 이벤트와 함께 필터를 제공합니다. 이 필터는 없음(기본값), 메타 데이터데이터와메타데이터. 다음 유형의 이벤트가 지원됩니다.

  • - 아이템 레벨 이벤트: 특정 캐시 항목(키 기반)이 업데이트되거나 캐시에서 제거될 때마다 알림을 받도록 등록된 클라이언트이며 이에 대한 콜백을 제공합니다. 이 항목이 업데이트되거나 제거되면 클라이언트에 알림이 전송됩니다.
  • - 캐시 레벨 이벤트: 캐시 레벨 이벤트는 모든 클라이언트 애플리케이션이 연결된 클라이언트 애플리케이션의 캐시 수정 사항에 대해 알림을 받아야 할 때 유용할 수 있는 일반 이벤트입니다.

아래 코드는 아이템 레벨 이벤트 등록을 보여줍니다.

public static void RegisterItemLevelEvents()
{
	// Get cache
	string cacheName = "demoCache";
	var cache = CacheManager.GetCache(cacheName); 

	// Register Item level events
	string key = "Product:1001";
	cache.MessagingService.RegisterCacheNotification(key, CacheDataNotificationCallbackImpl, EventType.ItemUpdated | EventType.ItemUpdated | EventType.ItemRemoved, EventDataFilter.DataWithMetadata);
}
public static void CacheDataNotificationCallbackImpl(string key, CacheEventArg cacheEventArgs)
{
	switch (cacheEventArgs.EventType)
	{
	   case EventType.ItemAdded:
		   // 'key' has been added to the cache
		   break;
	   case EventType.ItemUpdated:
		   // 'key' has been updated in the cache
		   break;
	   case EventType.ItemRemoved:
		   // 'key' has been removed from the cache
		   break;
	}
}
private static void RegisterItemLevelEvents() throws Exception {
        String cacheName = "demoCache";

        // Initialize an instance of the cache to begin performing operations:
        Cache cache = CacheManager.getCache(cacheName);
        String key = "Product:1001";
        cache.getMessagingService().addCacheNotificationListener(key, new CacheDataModificationListenerImpl(), EnumSet.allOf(EventType.class), EventDataFilter.DataWithMetadata);
    }
private static class CacheDataModificationListenerImpl implements CacheDataModificationListener {
	@Override
	public void onCacheDataModified(String key, CacheEventArg eventArgs) {
		switch (eventArgs.getEventType())
		{
			case ItemAdded:
				// 'key' has been added to the cache
				break;
			case ItemUpdated:
				// 'key' has been updated in the cache
				break;
			case ItemRemoved:
				// 'key' has been removed from the cache
				break;
		}
	}
	@Override
	public void onCacheCleared(String cacheName) {
		//cacheName cleared
	}
}

캐시 수준 이벤트의 경우 항목 수준 이벤트에 사용된 것과 동일한 콜백을 사용할 수 있습니다.

public static void RegisterCacheLevelEvents()
{
	// Get cache
	string cacheName = "demoCache";
	var cache = CacheManager.GetCache(cacheName);

	// Register cache level events
	cache.MessagingService.RegisterCacheNotification(EventsSample.CacheDataNotificationCallbackImpl, EventType.ItemUpdated | EventType.ItemUpdated | EventType.ItemRemoved, EventDataFilter.DataWithMetadata); 
}
private static void RegisterCacheLevelEvents() throws Exception {
	String cacheName = "demoCache";

	// Initialize an instance of the cache to begin performing operations:
	Cache cache = CacheManager.getCache(cacheName);

	CacheEventDescriptor eventDescriptor = cache.getMessagingService().addCacheNotificationListener(new CacheDataModificationListenerImpl(), EnumSet.allOf(EventType.class), EventDataFilter.DataWithMetadata);
}
 

NCache?

럭셔리 .NET 및 자바 응용 프로그램 NCache 높은 트랜잭션 Pub/Sub 메시징, 연속 쿼리 및 이벤트를 수행하는 데 이상적인 선택입니다. 여기 이유가 있습니다.

  • 초고속 및 확장성: NCache 완전히 메모리에 있기 때문에 매우 빠르며 밀리초 미만의 응답 시간을 제공합니다. 그리고 캐시 클러스터에 서버를 추가하여 선형 확장성을 달성하고 극도의 트랜잭션 로드를 처리합니다..
  • 데이터 복제를 통한 고가용성: NCache 성능 저하 없이 캐시의 데이터를 지능적으로 복제합니다. 따라서 캐시 서버가 다운되더라도 데이터(이벤트 및 메시지)를 잃지 않습니다.
  • .NET 및 Java 앱 서로 메시지 보내기: NCache .NET 및 Java 애플리케이션이 공통 메시징 및 스트림 플랫폼을 공유하고 메시지를 JSON으로 직렬화하거나 JSON 문서를 메시지로 전송하여 서로 메시지를 보낼 수 있도록 합니다.

이를 통해 다음을 사용할 수 있습니다. NCache 강력하면서도 단순한 메시징 플랫폼으로 에 대해 자세히 알아보기 NCache 아래 링크에서 완전히 작동하는 30일 평가판을 다운로드하십시오.

다음에 무엇을할지?

최신 업데이트를 받으려면 월간 이메일 뉴스레터에 가입하세요.

© 저작권 Alachisoft 2002 - . 판권 소유. NCache 는 Diyatech Corp.의 등록상표입니다.