예제 #1
0
 private void Upload(List <SampleCode> codes)
 {
     try
     {
         using (ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient(_ip, _port))
         {
             if (client.Ping())
             {
                 //using (var trans = client.CreatePipeline())
                 //{
                 //    for (int i = 0; i < codes.Count; i++)
                 //    {
                 //        String value = Newtonsoft.Json.JsonConvert.SerializeObject(codes[i]);
                 //        trans.QueueCommand(r => r.AddItemToList(_Channel, value));
                 //    }
                 //    trans.Flush();
                 //}
                 for (int i = 0; i < codes.Count; i++)
                 {
                     HNCAPI.Data.HncMessage <SampleCode> msg = new HncMessage <SampleCode>();
                     msg.Header = "SampleData";
                     msg.Body   = codes[i];
                     String message = Newtonsoft.Json.JsonConvert.SerializeObject(msg);
                     client.PublishMessage(_Channel, message);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("publish Upload:" + ex.Message);
     }
 }
예제 #2
0
 public void Publish(TEvnt data)
 {
     using (var redisPublisher = new ServiceStack.Redis.RedisClient(_host, _port))
     {
         try
         {
             redisPublisher.PublishMessage(MainChannel, data.SerializeToJSON());
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             throw;
         }
     }
 }
예제 #3
0
        //private event EventHandler Disposing;
        //private void removeSubs(object sender, EventArgs e)
        //{
        //    subscription.UnSubscribeFromAllChannels();
        //    subscription.Dispose();
        //}

        public bool PushMessage(T message)
        {
            return(redis.PublishMessage(_channelName, message.ToJson <T>()) > 0);
        }