예제 #1
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     connection = natsConnection.GetConnection();
     logger.LogInformation("---------------------------------------------------------------");
     logger.LogInformation("-->Connecting to natssamplestream...");
     subscription = connection.SubscribeAsync("natssamplestream.samplesubject.timestamp.received.>");
     subscription.MessageHandler += SubscriptionArrived;
     logger.LogInformation("-->Connected to natssamplestream!");
     logger.LogInformation("---------------------------------------------------------------");
     subscription.Start();
     return(Task.CompletedTask);
 }
예제 #2
0
        public async Task SendAsync(CloudEvent cloudEvent)
        {
            IConnection connection = natsConnection.GetConnection();

            connection.ResetStats();
            string json = JsonSerializer.Serialize(cloudEvent);
            Msg    msg  = await connection.RequestAsync($"{cloudEvent.Subject}.{cloudEvent.Id}", Encoding.UTF8.GetBytes(json), 10000);

            string decodedMessage = Encoding.UTF8.GetString(msg.Data);

            logger.LogInformation($"Response from NATS is: {decodedMessage}");
        }