Esempio n. 1
0
        /// <summary>
        /// Publish publishes the data argument to the given subject. The data
        /// argument is left untouched and needs to be correctly interpreted on
        /// the receiver.  This API is asynchronous and handles the acknowledgement
        /// or error from the NATS streaming server in the provided handler.  An exception is thrown when
        /// an error occurs during the send, the handler will process acknowledgments and errors.
        /// </summary>
        /// <typeparam name="TMessage">The message type.</typeparam>
        /// <param name="connection">The conmnection.</param>
        /// <param name="subject">Subject to publish the message to.</param>
        /// <param name="data"></param>
        /// <returns>The task object representing the asynchronous operation, containing the guid.</returns>
        public static async Task <string> PublishAsync <TMessage>(this IStanConnection connection, string subject, TMessage data)
            where TMessage : class, IRoundtripData, new()
        {
            Covenant.Requires <ArgumentNullException>(data != null);

            return(await connection.PublishAsync(subject, data.ToBytes()));
        }
Esempio n. 2
0
        public async Task PublishAsync()
        {
            Assert.Equal(ConnState.CONNECTED, connection.NATSConnection.State);

            StanMsg <Person> received = null;

            using (var subscription = connection.Subscribe <Person>("subject",
                                                                    (sender, args) =>
            {
                received = args.Msg;
                received.Ack();
            }))
            {
                var jack = new Person()
                {
                    Id   = 1,
                    Name = "Jack",
                    Age  = 10,
                    Data = new byte[] { 0, 1, 2, 3, 4 }
                };

                await connection.PublishAsync("subject", jack);

                NeonHelper.WaitFor(() => received != null, TimeSpan.FromSeconds(5));
                Assert.True(received.Data == jack);
            }
        }
Esempio n. 3
0
 public void PublishAsync(string subject, byte[] data)
 {
     if (conn != null && conn.NATSConnection.State == ConnState.CONNECTED)
     {
         subject = $"{producID}_{subject}";
         conn.PublishAsync(subject, data);
     }
 }
Esempio n. 4
0
 public void PublishAsync(string subject, byte[] data)
 {
     if (conn != null &&
         conn.NATSConnection.State == ConnState.CONNECTED &&
         scApp.getEQObjCacheManager().getLine().ServiceMode == SCAppConstants.AppServiceMode.Active)
     {
         subject = $"{producID}_{subject}";
         conn.PublishAsync(subject, data);
     }
 }
Esempio n. 5
0
 public async Task SendAsync(string topic, object message)
 {
     await _connection.PublishAsync(topic, message.SerializeToByteArray());
 }
Esempio n. 6
0
 public async Task <string> PublishAsync(string subject, T data)
 {
     return(await _stanClient.PublishAsync(subject, Encoding.UTF8.GetBytes(JsonSerializer.Serialize <T>(data))));
 }