TestJson() { Fang.Serialization.DataContractJson.Provider provider0 = new Fang.Serialization.DataContractJson.Provider(); Fang.Serialization.Formater<QueueTest, System.IO.Stream> formater = new Serialization.Formater<QueueTest, System.IO.Stream>() { Provider = provider0 }; Fang.MSMQ.Queue<QueueTest> queue = , Serializer = formater, Deserializer = formater }; queue.Init(); QueueChannel<QueueTest> channel = new QueueChannel<QueueTest>() { QueueBuffer = queue, }; Produce<QueueTest> producer = new Produce<QueueTest>() { }; channel.AddProducer(producer); channel.Init(); channel.Start(); producer.SendMessage( }); }
在新的消息队列中使用Json序列化的方式发的
6、MSMQ消息队列非常简单,公布源代码给大家看一下(还没完全写完,很多功能待完善)
MSMQ队列 Queue<TEntity> : Formatter<TEntity>, IEntityQueue<TEntity>, IUnitInit { #region 定义 Queue() { Host = ; Path = ; Name = ; BufferSize = Int16.MaxValue; if (ReceiveTimeOut < 1) ReceiveTimeOut = 1000D; _receiveTime = TimeSpan.FromMilliseconds(ReceiveTimeOut); } private MessageQueue _provider; 队列功能支持原始对象 MessageQueue Provider { get { return _provider; } } private TimeSpan _receiveTime; Path { get; set; } Name { get; set; } 主机 Host { get; set; } 单位(Millisecond) ReceiveTimeOut { get; set; } #endregion #region IEntityQueue<TEntity> TryDequeue(ref TEntity entity) { if (_provider == null) return false; Message message = null; try { message = _provider.Receive(_receiveTime); } catch { return false; } if (message == null) return false; return Transform.TryConvert<object, TEntity>(message.Body, ref entity); } TEntity Dequeue() { TEntity entity = default(TEntity); TryDequeue(ref entity); return entity; } Enqueue(TEntity entity) { if (entity == null || _provider == null) return false; Message message = new Message(); message.Body = entity; message.Formatter = this; try { _provider.Send(message); } catch { return false; } return true; } BufferSize { get; set; } Count() { if (_provider == null) return 0; return 100; } #endregion #region IUnitInit 初始化 Init() { , Path, , Name); if (!MessageQueue.Exists(fullName)) { MessageQueue.Create(fullName); } _provider = new MessageQueue(fullName); _provider.Formatter = this; } 清空 Clear() { if (_provider == null) return; _provider.Purge(); } //public static string CreatePath(string host,string path) //{ //} }
Queue