/// <summary> /// 创建一个新的单向通信事务 /// <para>* 使用此函数创建的事务是单向通信的,也就意味着新的事务不会触发RecvRsp事件</para> /// </summary> /// <param name="role">针对的服务角色</param> /// <param name="userId">需要定位的用户编号</param> /// <returns>返回新的事务</returns> /// <exception cref="ArgumentNullException">参数不能为空</exception> public BusinessMessageTransaction CreateOnewayTransaction(string role, int userId) { if (string.IsNullOrEmpty(role)) { throw new ArgumentNullException("role"); } string errMsg; IServerConnectionAgent <BaseMessage> agent = _clsuter.GetChannelBySpecificCondition(role, _protocolStacks[role], userId, out errMsg); return(agent == null ? new FailMobiSageMessageTransaction(errMsg) : new BusinessMessageTransaction(new Lease(DateTime.MaxValue), agent.GetChannel()) { Identity = IdentityHelper.CreateOneway((IPEndPoint)agent.GetChannel().LocalEndPoint) }); }
/// <summary> /// 创建一个新的单向通信事务 /// <para>* 使用此函数创建的事务是单向通信的,也就意味着新的事务不会触发RecvRsp事件</para> /// </summary> /// <param name="targetRole">针对的服务角色</param> /// <param name="protocolSelf">使用的协议栈</param> /// <returns>返回新的事务</returns> /// <exception cref="ArgumentNullException">参数不能为空</exception> public BusinessMessageTransaction CreateOnewayTransaction(string targetRole, string protocolSelf) { if (string.IsNullOrEmpty(targetRole)) { throw new ArgumentNullException("targetRole"); } if (string.IsNullOrEmpty(protocolSelf)) { throw new ArgumentNullException("protocolSelf"); } string errMsg; IServerConnectionAgent <BaseMessage> agent = _clsuter.GetChannel(protocolSelf, _protocolStacks[protocolSelf], out errMsg); return(agent == null ? new FailMobiSageMessageTransaction(errMsg) : new BusinessMessageTransaction(new Lease(DateTime.MaxValue), agent.GetChannel()) { Identity = IdentityHelper.CreateOneway((IPEndPoint)agent.GetChannel().LocalEndPoint) }); }
/// <summary> /// 创建一个新的网络事务 /// </summary> /// <param name="appName">目标APP的名称</param> /// <param name="target">标示网络终点接的协议簇组合</param> /// <param name="maximumRspTime">等待当前网络事务RSP消息的最大时间</param> /// <param name="resourceUri">KAE资源URI</param> /// <param name="balanceFlag">负载标识</param> /// <param name="communicationType">通信方式</param> /// <param name="version"> /// 目标APP的版本 /// <para>* 默认为: latest</para> /// </param> /// <param name="protocolSelf"> /// 使用的协议栈的角色 /// <para>* 如果当前事务代理器所承载的消息协议为MetadataContainer时请忽略此参数</para> /// </param> /// <returns>返回新的事务</returns> public IMessageTransaction <TMessage> CreateTransaction(string appName, Protocols target, TimeSpan maximumRspTime, long balanceFlag, string version = "latest", KAEResourceUri resourceUri = null, NetworkCommunicationTypes communicationType = NetworkCommunicationTypes.Dulplex, string protocolSelf = null) { if (string.IsNullOrEmpty(appName)) { throw new ArgumentNullException("appName"); } string errMsg; ApplicationLevel level = (resourceUri == null ? ApplicationLevel.Stable : _callback(resourceUri)); KAERingNode ringNode; IServerConnectionAgent <TMessage> agent = _cluster.GetChannel(target, level, _container.GetDefaultProtocolStack(_cluster.ProtocolType), balanceFlag, out errMsg, out ringNode); if (agent == null) { lock (_lockObj) { //try to obtains agent object again for ensuring that the newest remoting addresses can be appliy in the multiple threading env. agent = _cluster.GetChannel(target, level, _container.GetDefaultProtocolStack(_cluster.ProtocolType), balanceFlag, out errMsg, out ringNode); if (agent == null && !GetMissedRemoteAddresses(appName, version, target, level)) { return(new FailMessageTransaction <TMessage>(errMsg)); } agent = _cluster.GetChannel(target, level, _container.GetDefaultProtocolStack(_cluster.ProtocolType), balanceFlag, out errMsg, out ringNode); //check returned value again for avoiding couldnt connect to the remote address now. if (agent == null) { return(new FailMessageTransaction <TMessage>(errMsg)); } } } MessageTransaction <TMessage> transaction = NewTransaction(new Lease(DateTime.Now.Add(maximumRspTime)), agent.GetChannel()); transaction.SetMessageIdentity(new MessageIdentity { ProtocolId = (byte)target.ProtocolId, ServiceId = (byte)target.ServiceId, DetailsId = (byte)target.DetailsId }); transaction.TransactionManager = _transactionManager; transaction.Identity = (communicationType == NetworkCommunicationTypes.Dulplex ? IdentityHelper.Create(agent.GetChannel().LocalEndPoint, TransportChannelTypes.TCP) : IdentityHelper.CreateOneway(agent.GetChannel().LocalEndPoint, TransportChannelTypes.TCP)); transaction.KPPUniqueId = ringNode.KPPUniqueId; return(_transactionManager.Add(transaction.Identity, transaction) ? transaction : null); }
/// <summary> /// 创建一个新的单向事务 /// </summary> /// <returns>返回新创建的单向事务</returns> /// <exception cref="ArgumentNullException">参数错误</exception> public MessageTransaction <BaseMessage> CreateOnewayTransaction() { return(_transactionManager.Create(IdentityHelper.CreateOneway(_channel.LocalEndPoint, _channel.ChannelType), _channel)); }