Created
February 5, 2022 14:35
-
-
Save alexandrebl/4e5067eae50c73076d43a149b67c240c to your computer and use it in GitHub Desktop.
NATS.io.Subject.Based.Messaging.Publisher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
natspub "subject" "message"