v9.8.2018.0605   由DataReader直接映射实体列表,以支持netstandard的MySql和SQLite,且提升性能
大石头 authored at 2018-06-05 00:45:23
1.37 KiB
X
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NewLife.Remoting;

namespace NewLife.Queue.Broker.Controllers
{
    public class ProducerInfoController : IApi
    {
        public IApiSession Session { get; set; }

        public bool RegisterProducer(string user,string pass)
        {
            var host = Session.GetService<ApiServer>();
            var producerInfoDict = host["ProducerInfoDict"] as ConcurrentDictionary<string, ProducerInfo>;
            if (producerInfoDict == null) return false;
            producerInfoDict.AddOrUpdate(Session.Remote.EndPoint.ToAddress(), key =>
            {
                var producerInfo = new ProducerInfo
                {
                    ProducerId = Session.Remote.EndPoint.ToAddress(),
                    HeartbeatInfo = new ClientHeartbeatInfo(Session) { LastHeartbeatTime = DateTime.Now }
                };
                host.Log.Info("Producer registered, producerId: {0}, connectionId: {1}", Session.Remote.EndPoint.ToAddress(), key);
                return producerInfo;
            }, (key, existingProducerInfo) =>
            {
                existingProducerInfo.HeartbeatInfo.LastHeartbeatTime = DateTime.Now;
                return existingProducerInfo;
            });
            return true;
        }
    }
}