• Facebook
  • Twitter
  • Youtube
  • Allineato
  • RSS
  • Docs
  • Confronti
  • Blog
  • Scaricare
  • Contattaci
Scaricare
Mostra/Nascondi sommario

Argomenti Pub/Sub

A Argomento contiene il messaggio stesso, insieme a informazioni aggiuntive sull'abbonato e sull'editore. Il ITopic/Topic l'interfaccia in Pub/Sub facilita creazione di un argomento, Impostazione della priorità dell'argomento durante la creazione, recupero di un argomento, eliminazione sincrona di un argomento or in modo asincrono.

Prerequisiti

Prima di usare il NCache Per le API lato client, assicurarsi che siano soddisfatti i seguenti prerequisiti:

  • .NET
  • Java
  • Python
  • Node.js
  • API legacy
  • Installa i seguenti pacchetti NuGet nella tua applicazione client .NET:
    • Impresa: Alachisoft.NCache.Sdk
    • Open Source: Alachisoft.NCache.SDK open source
  • Includere i seguenti spazi dei nomi nell'applicazione:
    • Alachisoft.NCache.Cliente
    • Alachisoft.NCache.Eccezioni.di.runtime
    • Alachisoft.NCache.Memorizzazione.della.cache
  • La cache deve essere in esecuzione.
  • Assicurati che i dati aggiunti lo siano serializzabile.
  • Per i dettagli dell'API, fare riferimento a: ICache, CacheItem, Argomento, Crea argomento, GetTopic, Elimina argomento, Priorità argomento, EliminaargomentoAsync, Servizio di messaggistica.
  • Aggiungi le seguenti dipendenze Maven per la tua applicazione client Java in pom.xml file:
<dependency>
    <groupId>com.alachisoft.ncache</groupId>
    <!--for NCache Enterprise-->
    <artifactId>ncache-client</artifactId>
    <version>x.x.x</version>
</dependency>
  • Importa i seguenti pacchetti nell'applicazione client Java:
    • importare com.alachisoft.ncache.client.*;
    • importare com.alachisoft.ncache.runtime.eccezione.*;
    • importare com.alachisoft.ncache.runtime.caching.*;
  • La cache deve essere in esecuzione.
  • Assicurati che i dati aggiunti lo siano serializzabile.
  • Per i dettagli dell'API, fare riferimento a: Cache, CacheItem, Argomento, createTopic, getTopic, elimina argomento, getMessagingService, deleteTopicAsync, Priorità argomento.
  • Installa i seguenti pacchetti nella tua applicazione client Python:
    • Impresa: client ncache
  • Importa i seguenti pacchetti nella tua applicazione:
    • da ncache.client importazione*
    • da importazione ncache.runtime*
    • da ncache.runtime.caching importazione *
    • da ncache.client.services importazione *
  • La cache deve essere in esecuzione.
  • Assicurati che i dati aggiunti lo siano serializzabile.
  • Per i dettagli dell'API, fare riferimento a: Cache, CacheItem, crea_argomento, get_topic, elimina_argomento, Priorità argomento, get_messaging_service, elimina_argomento_asincrono.
  • Installa e includi il seguente modulo nella tua applicazione client Node.js:

    • Impresa: client ncache
  • Includi la seguente classe nella tua applicazione:

    • Cache
    • Argomento
    • Sottoscrizione all'argomento
  • La cache deve essere in esecuzione.
  • Assicurati che i dati aggiunti lo siano serializzabile.
  • Per i dettagli dell'API, fare riferimento a: Cache, CacheItem, createTopic, getTopic, elimina argomento, Priorità argomento, Servizio di messaggistica, getMessagingService.
  • Installa uno dei seguenti pacchetti NuGet nella tua applicazione client .NET:
    • Enterprise: Install-Package Alachisoft.NCache.SDK -Version 4.9.1.0
  • Crea una nuova applicazione console.
  • Assicurati che i dati aggiunti lo siano serializzabile.
  • Aggiungi NCache Referenze individuando %NCHOME%\NCache\bin\assembly\4.0 e aggiungendo Alachisoft.NCache.Web and Alachisoft.NCache.Runtime come appropriato.
  • Includi il Alachisoft.NCache.Web.Caching and Alachisoft.NCache.Runtime.Caching spazi dei nomi nella tua applicazione.
  • Per saperne di più sul NCache API legacy, scaricala NCache 4.9 documenti disponibili come file .zip file sul Alachisoft Sito web.

Come creare un argomento Pub/Sub in NCache

Migliori Crea argomento il metodo crea un Argomento nella cache con un nome specificato. Se l'Argomento esiste già, viene restituita un'istanza dell'Argomento come ITopicOgni volta che un messaggio viene pubblicato su un argomento, viene recapitato in base alle preferenze degli iscritti registrati su quell'argomento. L'esempio seguente crea un argomento. ordineArgomento.

  • .NET
  • Java
  • Python
  • Node.js
  • API legacy
try
{
  // Precondition: Cache is already connected

  // Mention the name of the Topic
  string topicName = "orderTopic";

  // Create the Topic
  ITopic topic = cache.MessagingService.CreateTopic(topicName);
}
catch (OperationFailedException ex)
{
    // Exception can occur due to:
    // Connection Failures
    // Operation Timeout
    // Operation performed during state transfer
}
catch (Exception ex)
{
    // Any other generic exception like ArgumentNullException or ArgumentException
    // Topic name is null/empty
}
try
{
  // Precondition: Cache is already connected

  // Mention the name of the Topic
  String topicName = "orderTopic";

  // Create the Topic
  Topic topic = cache.getMessagingService().createTopic(topicName);
}
catch (OperationFailedException ex) 
{
    // Exception can occur due to:
    // Connection Failures
    // Operation Timeout
    // Operation performed during state transfer
} 
catch(Exception ex) 
{
    // Any generic exception like IllegalArgumentException or NullPointerException
}
try:
# Precondition: Cache is already connected

# Mention the name of the Topic
topic_name = "orderTopic"

# Create the Topic
topic = cache.get_messaging_service().create_topic(topic_name)

except Exception as ex:
    # Exception can occur due to:
    # - Connection failures
    # - Operation timeout
    # - Invalid arguments (e.g., null/empty topic name)
    print("Operation failed: " + str(ex))
try
{
  // This is an async method
  // Precondition: Cache is already connected

  // Mention the name of the Topic
  let topicName = "orderTopic";

  // Create the Topic
  let messagingService = await cache.getMessagingService();
  let topic = await messagingService.createTopic(topicName);
}
catch (error) {
  // Handle any errors
}
try
{
  // Using NCache Enterprise 4.9.1
  // Precondition: Cache is already connected

  // Mention the name of the Topic
  string topicName = "orderTopic";

  // Create the Topic
  cache.MessagingService.CreateTopic(topicName);
}
catch (OperationFailedException ex)
{
    // Exception can occur due to:
    // Connection Failures
    // Operation Timeout
    // Operation performed during state transfer
}
catch (Exception ex)
{
    // Any other generic exception like ArgumentNullException or ArgumentException
    // Topic name is null/empty
}
Note:

Per garantire che l'operazione sia a prova di errore, si consiglia di gestire eventuali potenziali eccezioni all'interno dell'applicazione, come spiegato in Gestione dei guasti.

Crea argomento con priorità

Note:

Questa funzione è disponibile solo in NCache Dal 5.2 in poi.

NCache Pub/Sub consente di impostare Priorità dell'argomento dare priorità alla consegna dei messaggi critici. La priorità viene specificata utilizzando il file TopicPriority proprietà come Low, Normale HighSe l'eliminazione è abilitata, gli argomenti con la priorità più bassa vengono eliminati per primi, mentre gli argomenti con la priorità più alta vengono eliminati per ultimi. Gli argomenti creati senza priorità specificata verranno creati con la priorità predefinita, ovvero Normale. L'esempio seguente crea un argomento, ordineArgomento, con priorità alta per evitare lo sfratto anticipato (se lo sfratto è abilitato).

Consigli

La priorità di un argomento può essere specificata solo al momento della creazione dell'argomento e non può essere modificata in seguito.

  • .NET
  • Java
  • Python
  • Node.js
// Precondition: Cache is already connected

// Mention the name of the Topic
string topicName = "orderTopic";

// Create the Topic with priority
ITopic topic = cache.MessagingService.CreateTopic(topicName, Alachisoft.NCache.Runtime.Messaging.TopicPriority.High);
// Precondition: Cache is already connected

// Mention the name of the Topic
String topicName = "orderTopic";

// Create the Topic with priority
Topic topic = cache.getMessagingService().createTopic(topicName, TopicPriority.High);
# Precondition: Cache is already connected

# Mention the name of the Topic
topic_name = "orderTopic"

# Create the Topic
topic = cache.get_messaging_service().create_topic(topic_name, ncache.TopicPriority.HIGH)
// Precondition: Cache is already connected

// This is an async method

 // Mention the name of the Topic
let topicName = "orderTopicPriority";


// Create Topic with priority
let messagingService = await cache.getMessagingService();
let topic = await messagingService.createTopic(topicName, ncache.TopicPriority.High);

Ottieni argomento

Migliori GetTopic Il metodo recupera un'istanza dell'argomento specificato dalla cache. Se l'argomento esiste, viene restituito; altrimenti, viene restituito null. L'esempio seguente recupera un argomento esistente ordineArgomento dalla cache.

  • .NET
  • Java
  • Python
  • Node.js
  • API legacy
// Precondition: Cache is already connected

// Mention the name of the Topic
string topicName = "orderTopic";

// Get the Topic from the cache
ITopic orderTopic = cache.MessagingService.GetTopic(topicName);

// Verify successful Topic retrieval
if (orderTopic != null)
{
    // orderTopic will be used for receiving and/or publishing messages
}
else
{
    // No Topic exists
}
// Precondition: Cache is already connected

// Mention name of the Topic
String topicName = "orderTopic";

// Get the Topic
Topic orderTopic = cache.getMessagingService().getTopic(topicName);

// Verify successful Topic retrieval
if (orderTopic != null) 
{
    // orderTopic will be used for receiving and/or publishing messages
} else 
{
    // No Topic exists
}
# Precondition: Cache is already connected

# Mention name of the Topic
topic_name = "orderTopic"

# Get the Topic from the cache
order_topic = cache.get_messaging_service().get_topic(topic_name)

# Verify successful Topic retrieval
if order_topic is not None:
    # order_topic will be used for receiving and/or publishing messages
else:
    # No Topic exists
// Precondition: Cache is already connected

// This is an async method

// Mention the name of the Topic
let topicName = "orderTopic";

// Get the Topic from the cache
let messagingService = await cache.getMessagingService();
let orderTopic = await messagingService.getTopic(topicName);

// Verify successful Topic retrieval
if (!(orderTopic == null)) 
{
    // orderTopic will be used for receiving and/or publishing messages
} 
else 
{
    // No Topic exists
}
// Using NCache Enterprise 4.9.1
// Precondition: Cache is already connected

// Mention the name of the Topic
string topicName = "orderTopic";

// Get the Topic from the cache
ITopic orderTopic = cache.MessagingService.GetTopic(topicName);

// Verify successful Topic retrieval
if (orderTopic != null)
{
    // orderTopic will be used for receiving and/or publishing messages
}
else
{
    // No Topic exists
}

Elimina argomento

Migliori Elimina argomento Il metodo annulla la registrazione dell'argomento dalla cache e rimuove tutti i messaggi associati a tale argomento. Se registrato, viene eseguita una callback di eliminazione dell'argomento OnTopicDeleted verrà attivato su questa chiamata di metodo. Il seguente esempio elimina l'argomento esistente ordineArgomento dalla cache e rimuove tutti i messaggi associati a quell'argomento. Se il OnTopicDeleted callback è registrato, verrà attivato su questa chiamata al metodo.

  • .NET
  • Java
  • Python
  • Node.js
  • API legacy
// Precondition: Cache is already connected

// Define the Topic to be deleted
string topicName = "orderTopic";

// Delete the Topic "orderTopic"
cache.MessagingService.DeleteTopic(topicName);

// Callback will be triggered if registered
// Precondition: Cache is already connected

// Mention the Topic to be deleted
String topicName = "orderTopic";

// Delete the Topic
cache.getMessagingService().deleteTopic(topicName);

// Callback will be triggered if registered
# Precondition: Cache is already connected

# Define the Topic to be deleted
topic_name = "orderTopic"

# Delete the Topic "orderTopic"
cache.get_messaging_service().delete_topic(topic_name)

# Callback will be triggered if registered
// Precondition: Cache is already connected

// Mention the Topic to be deleted
let topicName = "orderTopic";

// Delete the Topic
let messagingService = await cache.getMessagingService();
await messagingService.deleteTopic(topicName);

// Callback will be triggered if registered
// Using NCache Enterprise 4.9.1
// Precondition: Cache is already connected

// Define the Topic to be deleted
string topicName = "orderTopic";

// Delete the Topic "orderTopic"
cache.MessagingService.DeleteTopic(topicName);

// Callback will be triggered if registered

Elimina argomento in modo asincrono

Migliori EliminaargomentoAsync metodo elimina l'argomento in modo asincrono. Ogni volta che un argomento viene eliminato in modo asincrono, un Task viene restituito all'utente per eseguire ulteriori attività senza attendere che l'argomento venga eliminato. L'esempio seguente mostra l'eliminazione asincrona dell'argomento ordineArgomento.

  • .NET
  • Java
  • Python
// Precondition: Cache is already connected

// Define the Topic to be deleted
string topicName = "orderTopic";

// Delete the Topic "orderTopic"
Task task = cache.MessagingService.DeleteTopicAsync(topicName);

// Use task to perform further operations according to business logic
// Callback will be triggered if registered
// Precondition: Cache is already connected

// Mention the Topic to be deleted
String topicName = "orderTopic";

// Delete the Topic asynchronously
TimeScheduler.Task task = (TimeScheduler.Task) cache.getMessagingService().deleteTopicAsync(topicName);

// Use tasks to perform further operations according to business logic
// Callback will be triggered if registered
# Precondition: Cache is already connected

# Mention the Topic to be deleted
topic_name = "orderTopic"

# Delete the Topic asynchronously
task = await cache.get_messaging_service().delete_topic_async(topic_name)

# Use tasks to perform further operations according to business logic
# Callback will be triggered if registered

Proprietà dell'interfaccia ITopic

Utenti Tipo Descrizione
MessageDeliveryFailure MessageDeliveryFailureCallback Evento sull'argomento in modo che l'editore riceva tutti i messaggi non recapitati che non sono stati recapitati ad alcun abbonato o che potrebbero essere scaduti o eliminati prima della consegna.
Name string Nome dell'argomento specificato durante la creazione dell'argomento.
OnTopicDeleted TopicDeletedCallback Evento per gestire l'eliminazione dell'argomento da parte dell'editore e dell'abbonato.
ExpirationTime TimeSpan Se non viene fornita la scadenza a livello di messaggio, questa scadenza a livello di argomento fa scadere i messaggi nell'argomento per impostazione predefinita. Il valore è TimeSpan.MaxValue per impostazione predefinita.
IsClosed bool Prima di eseguire qualsiasi operazione, verificare che l'argomento sia stato eliminato.
Dispose IDisposable Rimuove l'abbonamento dell'argomento registrato dal server cache.

Risorse addizionali

NCache fornisce un'applicazione di esempio per Pub/Sub su GitHub.

Vedere anche

.NETTO: Alachisoft.NCache.Memorizzazione.della.cache spazio dei nomi.
Giava: com.alachisoft.ncache.runtime.caching pacchetto.
Pitone: servizi.ncache.client modulo.
Node.js: Argomento classe.

Contattaci

PHONE

+1 214-619-2601   (US)

+44 20 7993 8327   (UK)

 
E-MAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • Confronto edizione
  • NCache Architettura
  • Parametri di riferimento
Scaricare
Prezzi
Prova Parco giochi

Distribuzioni
  • Cloud (SaaS e software)
  • On-Locale
  • kubernetes
  • docker
Casi d'uso tecnici
  • Sessioni ASP.NET
  • Sessioni ASP.NET Core
  • Messaggistica Pub/Sub
  • SignalR in tempo reale per ASP.NET
  • Internet of Things (IoT)
  • Database NoSQL
  • Streaming Processing
  • Microservices
Risorse
  • Articoli di riviste
  • Articoli di terze parti
  • Articoli
  • Video
  • Fogli bianchi
  • Spettacoli
  • trattativa
  • Blog
  • Docs
Casi di studio dei clienti
  • Testimonianze
  • Clienti
Assistenza
  • Pianificare un demo
  • Forum (Google Gruppi)
  • Consigli
Azienda
  • Leadership
  • Partner
  • News
  • Eventi
  • Lavora con noi
Contattaci

  • IngleseCinese (semplificato)FranceseTedescoItalianoGiapponeseCoreanoPortogheseCorsi

  • Contattaci
  •  
  • Mappa del sito
  •  
  • Termini d’uso
  •  
  • Informativa privacy
© Copyright Alachisoft 2002 - . Tutti i diritti riservati. NCache è un marchio registrato di Diyatech Corp.
Torna in alto