Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save alexandrebl/4e5067eae50c73076d43a149b67c240c to your computer and use it in GitHub Desktop.

Select an option

Save alexandrebl/4e5067eae50c73076d43a149b67c240c to your computer and use it in GitHub Desktop.
NATS.io.Subject.Based.Messaging.Publisher
using NATS.Client;
using System;
using System.Text;
using System.Threading;
namespace NatsPub1
{
internal class Program
{
static void Main(string[] args)
{
// Define as variáveis
var subscription = GetSubscription(args);
var message = GetMessage(args);
// Obtem a conexão
var connection = GetConnection();
// Publica a mensagem
connection.Publish(subscription, Encoding.UTF8.GetBytes(message));
Console.WriteLine($"{DateTime.Now:F} - Subscription: {subscription} - Send: {message}");
}
/// <summary>
/// Obtem a assinatura
/// </summary>
/// <param name="args">argumentos de linha de comando</param>
/// <returns>assinatura</returns>
public static string GetSubscription(String[] args) => args[0];
/// <summary>
/// Obtem a mensagem a ser publicada
/// </summary>
/// <param name="args">argumentos de linha de comando</param>
/// <returns>mensagem</returns>
public static string GetMessage(String[] args) => args[1];
/// <summary>
/// Obtem uma nova conexão
/// </summary>
/// <returns>nova conexão com NATs.io</returns>
public static IConnection GetConnection()
{
var cf = new ConnectionFactory();
var c = cf.CreateConnection();
return c;
}
}
}
@alexandrebl
Copy link
Copy Markdown
Author

natspub "subject" "message"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment