public EventLinkClient(Uri baseUri, string partitionId, ErrorStateChangeCallback callback) { subscribeClient = new SubscribeClient(this, baseUri, partitionId); publishClient = new PublishClient(this, baseUri, partitionId); onErrorStateChange = callback; RetryPolicy = RetryPolicies.Retry(RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff); }
/// <summary> /// 发布 /// </summary> /// <param name="Topic">主题</param> /// <param name="publishString">发布内容</param> public void Client_MqttMsgPublish(string Topic, string publishString) { SubscribeClient.Publish(string.Format("GateWay/V1/{0}/RealTimeMsg", Topic.Replace("\"", "")), Encoding.UTF8.GetBytes(publishString), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false); //SubscribeClient.MqttMsgPublishReceived += Client_MqttMsgPublishReceived; }
bool Init() { if (context.Transport == null) { // init and open high/low latency transport, create protocols var lowLatencyPort = context.LowLatencyPort == 0 ? ConstantsSDKDataTypesConstants.low_latency_socket_port : context.LowLatencyPort; lowLatencyTransport = new TSocketTransportTS(context.RemoteAddress, lowLatencyPort, context.Timeout <= 0 ? SDKUtility.Instance.LowLatencyTimeout : context.Timeout); var highLatencyPort = context.HighLatencyPort == 0 ? ConstantsSDKDataTypesConstants.high_latency_socket_port : context.HighLatencyPort; highLatencyTransport = new TSocketTransportTS(context.RemoteAddress, highLatencyPort, context.Timeout <= 0 ? SDKUtility.Instance.HighLatencyTimeout : context.Timeout); } else { lowLatencyTransport = context.Transport; highLatencyTransport = context.Transport; } LowLatencyProtocol = new TBinaryProtocolTS(lowLatencyTransport); HighLatencyProtocol = new TBinaryProtocolTS(highLatencyTransport); lowLatencyTransport.Open(); highLatencyTransport.Open(); if (!ValidateVersion()) { return(false); } if (IsFeatureEnabled(SDKFeatures.Subscriber)) { var pubout = ConstantsSDKDataTypesConstants.layer0_publisher_out_uri.SetAddress(context.RemoteAddress); Subscriber = SubscribeClient.CreateInstance(pubout); } if (IsFeatureEnabled(SDKFeatures.Storage)) { var stoProtocol = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.STORAGELAYER.ServiceID()); Storage = new StorageLayerService.Client(stoProtocol); } if (IsFeatureEnabled(SDKFeatures.Online)) { var bcProtocol = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.BCSERVICE.ServiceID()); RuyiNetService = new RuyiNetClient(bcProtocol, Storage); //BCService = new BrainCloudService.Client(bcProtocal); } if (IsFeatureEnabled(SDKFeatures.Settings)) { var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.SETTINGSYSTEM_EXTERNAL.ServiceID()); SettingSys = new SDK.SettingSystem.Api.SettingSystemService.Client(proto); } if (IsFeatureEnabled(SDKFeatures.L10N)) { var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.L10NSERVICE.ServiceID()); L10NService = new LocalizationService.Client(proto); } if (IsFeatureEnabled(SDKFeatures.Users)) { var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.USER_SERVICE_EXTERNAL.ServiceID()); UserService = new UserServExternal.Client(proto); } if (IsFeatureEnabled(SDKFeatures.Input)) { var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.INPUTMANAGER_EXTERNAL.ServiceID()); InputMgr = new InputManagerService.Client(proto); } if (IsFeatureEnabled(SDKFeatures.Speech)) { var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.SPEECH.ServiceID()); SpeechService = new SpeechService.Client(proto); } if (IsFeatureEnabled(SDKFeatures.Media)) { var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.MEDIA.ServiceID()); Media = new MediaService.Client(proto); } if (IsFeatureEnabled(SDKFeatures.Overlay)) { var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.OVERLAYMANAGER_EXTERNAL.ServiceID()); OverlayService = new OverlayExternalService.Client(proto); } return(true); }