public ONSOrderConsumer(string topic, string consumerId, OrderConsumer consumer, Type classType) { ClassType = classType; Type = ONSMessageType.ORDER.ToString(); Topic = topic; ConsumerId = consumerId; _consumer = consumer; TagList = new List <string>(); }
public virtual OrderConsumer createOrderConsumer(ONSFactoryProperty factoryProperty) { global::System.IntPtr cPtr = ONSClient4CPPPINVOKE.ONSFactoryAPI_createOrderConsumer(swigCPtr, ONSFactoryProperty.getCPtr(factoryProperty)); OrderConsumer ret = (cPtr == global::System.IntPtr.Zero) ? null : new OrderConsumer(cPtr, false); if (ONSClient4CPPPINVOKE.SWIGPendingException.Pending) { throw ONSClient4CPPPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public override void Start() { if (this.listener == null) { throw new NotFoundMessageListenerException(); } consumer = ONSFactory.getInstance().createOrderConsumer(this.FactoryProperty); consumer.subscribe(Topic, SubExpression, listener); consumer.start(); }
static void Main(string[] args) { ONSFactoryProperty factoryInfo = new ONSFactoryProperty(); factoryInfo.setFactoryProperty(factoryInfo.getConsumerIdName(), "CID_5678"); Console.WriteLine("ProducerId:{0}, \nConsumerId:{1},\nPublishTopics:{2},\nMsgContent:{3},\nAccessKey::{4},\nSecretKey::{5} ", factoryInfo.getProducerId(), factoryInfo.getConsumerId(), factoryInfo.getPublishTopics(), factoryInfo.getMessageContent(), factoryInfo.getAccessKey(), factoryInfo.getSecretKey()); ONSFactory onsfactory = new ONSFactory(); OrderConsumer pConsumer = onsfactory.getInstance().createOrderConsumer(factoryInfo); MessageOrderListener msgListener = new MyMsgListener(); pConsumer.subscribe("Ram_Topic_2", "*", ref msgListener); pConsumer.start(); Thread.Sleep(10000 * 100); pConsumer.shutdown(); }
public static void CreateOrderConsumer() { _orderconsumer = ONSFactory.getInstance().createOrderConsumer(getFactoryProperty()); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(OrderConsumer obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
/// <summary> /// 初始化属性 /// </summary> static void InitializeProperties() { //实例化生产者的服务类列表 ONSProducerServiceList = new List <object>(); //实例化消费者的服务类列表 ONSConsumerServiceList = new List <object>(); //实例化生产者列表 ONSProducerList = new List <IONSProducer>(); //实例化消费者列表 ONSConsumerList = new List <IONSConsumer>(); //实例化Executer方法对应的委托实例字典 ExecuterMethodDictionary = new ConcurrentDictionary <string, MethodInfo>(); //实例化Checker方法对应的委托实例字典 CheckerMethodDictionary = new ConcurrentDictionary <string, MethodInfo>(); //* //获取当前应用域下的所有程序集 Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); //找出所有程序集下带有[ONSConsumer]特性的所有方法,并放入自定义消费者方法列表中 if (assemblies != null) { foreach (Assembly assembly in assemblies) { Type[] types = assembly.GetTypes(); if (types != null) { foreach (Type type in types) { if (type.BaseType != null) { if (type.BaseType.FullName != null) { //获取当前应用作为"事务"类型生产者的相关信息 CreateProducer <AbstractTranProducerService <object> >(assembly, type, ONSMessageType.TRAN, (onsProducerFactoryProperty, topic, producerId) => { //实例化ONSLocalTransactionChecker ONSLocalTransactionChecker checker = new ONSLocalTransactionChecker(); //实例化TransactionProducer TransactionProducer transactionProducer = ONSFactory.getInstance().createTransactionProducer(onsProducerFactoryProperty, checker); //实例化代理类ONSTransactionProducer return(new ONSTranProducer(topic, producerId, transactionProducer)); }); ////获取当前应用作为"顺序"类型生产者的相关信息 //CreateProducer<AbstractOrderProducerService<object>>(assembly, type, ONSMessageType.ORDER, (onsProducerFactoryProperty, topic, producerId) => //{ // //实例化OrderProducer // OrderProducer orderProducer = ONSFactory.getInstance().createOrderProducer(onsProducerFactoryProperty); // //实例化代理类ONSOrderProducer // return new ONSOrderProducer(topic, producerId, orderProducer); //}); ////获取当前应用作为"普通"类型生产者的相关信息 //CreateProducer<AbstractBaseProducerService<object>>(assembly, type, ONSMessageType.BASE, (onsProducerFactoryProperty, topic, producerId) => //{ // //实例化Producer // Producer baseProducer = ONSFactory.getInstance().createProducer(onsProducerFactoryProperty); // //实例化代理类ONSProducer // return new ONSBaseProducer(topic, producerId, baseProducer); //}); //获取当前应用作为"事务"类型消费者的相关信息 CreateConsumer <AbstractTranConsumerService <object> >(assembly, type, ONSMessageType.TRAN, (onsConsumerFactoryProperty, topic, consumerId, classType) => { //实例化PushConsumer PushConsumer pushConsumer = ONSFactory.getInstance().createPushConsumer(onsConsumerFactoryProperty); //实例化代理类ONSTransactionConsumer return(new ONSTranConsumer(topic, consumerId, pushConsumer, classType)); }); //获取当前应用作为"顺序"类型消费者的相关信息 CreateConsumer <AbstractOrderConsumerService <object> >(assembly, type, ONSMessageType.ORDER, (onsConsumerFactoryProperty, topic, consumerId, classType) => { //实例化OrderConsumer OrderConsumer orderConsumer = ONSFactory.getInstance().createOrderConsumer(onsConsumerFactoryProperty); //实例化代理类ONSOrderConsumer return(new ONSOrderConsumer(topic, consumerId, orderConsumer, classType)); }); //获取当前应用作为"普通"类型消费者的相关信息 CreateConsumer <AbstractBaseConsumerService <object> >(assembly, type, ONSMessageType.BASE, (onsConsumerFactoryProperty, topic, consumerId, classType) => { //实例化PushConsumer PushConsumer pushConsumer = ONSFactory.getInstance().createPushConsumer(onsConsumerFactoryProperty); //实例化代理类ONSTransactionConsumer return(new ONSBaseConsumer(topic, consumerId, pushConsumer, classType)); }); } } } } } } //*/ }
/// <summary> /// 初始化属性 /// </summary> static void InitializeProperties() { //实例化生产者的服务类列表 ONSProducerServiceList = new List <object>(); //实例化消费者的服务类列表 ONSConsumerServiceList = new List <object>(); //实例化生产者列表 ONSProducerList = new List <IONSProducer>(); //实例化消费者列表 ONSConsumerList = new List <IONSConsumer>(); //实例化Executer方法对应的委托实例字典 ExecuterMethodDictionary = new ConcurrentDictionary <string, MethodInfo>(); //实例化Checker方法对应的委托实例字典 CheckerMethodDictionary = new ConcurrentDictionary <string, MethodInfo>(); //* //获取当前应用域下的所有程序集 Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); //找出所有程序集下带有[ONSConsumer]特性的所有方法,并放入自定义消费者方法列表中 if (assemblies != null) { foreach (Assembly assembly in assemblies) { Type[] types = null; try { types = assembly.GetTypes(); } catch (Exception e) { //通过vs2017编译后反射会报错,需要捕捉错误。忽略此处错误即可 //Microsoft.Build.Tasks.CodeAnalysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 //尝试获取所有类时发生异常 /* * string body = assembly.FullName + "尝试获取所有类时发生异常:" + e.ToString(); * SendDebugMail("ONSHelper.InitializeProperties方法反射时捕获异常", body); * //*/ } if (types != null) { //* foreach (Type type in types) { if (type.BaseType != null) { if (type.BaseType.FullName != null) { //原本事务消息是需要自动注册,因为ProducerService必须开发者自己实现。但是在2019年01月23日大更新后,老SDK在生成Producer时不再需要输入ProducerId了,但是TranProducer实例化时会报错。因此这里禁用事务消息功能。 //获取当前应用作为"事务"类型生产者的相关信息 CreateProducer <AbstractTranProducerService <object> >(assembly, type, ONSMessageType.TRAN, (onsProducerFactoryProperty, topic, producerId) => { //实例化ONSLocalTransactionChecker ONSLocalTransactionChecker checker = new ONSLocalTransactionChecker(); //实例化TransactionProducer TransactionProducer transactionProducer = ONSFactory.getInstance().createTransactionProducer(onsProducerFactoryProperty, checker); //实例化代理类ONSTransactionProducer return(new ONSTranProducer(topic, producerId, transactionProducer)); }); ////获取当前应用作为"顺序"类型生产者的相关信息 //CreateProducer<AbstractOrderProducerService<object>>(assembly, type, ONSMessageType.ORDER, (onsProducerFactoryProperty, topic, producerId) => //{ // //实例化OrderProducer // OrderProducer orderProducer = ONSFactory.getInstance().createOrderProducer(onsProducerFactoryProperty); // //实例化代理类ONSOrderProducer // return new ONSOrderProducer(topic, producerId, orderProducer); //}); ////获取当前应用作为"普通"类型生产者的相关信息 //CreateProducer<AbstractBaseProducerService<object>>(assembly, type, ONSMessageType.BASE, (onsProducerFactoryProperty, topic, producerId) => //{ // //实例化Producer // Producer baseProducer = ONSFactory.getInstance().createProducer(onsProducerFactoryProperty); // //实例化代理类ONSProducer // return new ONSBaseProducer(topic, producerId, baseProducer); //}); //获取当前应用作为"事务"类型消费者的相关信息 CreateConsumer <AbstractTranConsumerService <object> >(assembly, type, ONSMessageType.TRAN, (onsConsumerFactoryProperty, topic, consumerId, classType) => { //实例化PushConsumer PushConsumer pushConsumer = ONSFactory.getInstance().createPushConsumer(onsConsumerFactoryProperty); //实例化代理类ONSTransactionConsumer return(new ONSTranConsumer(topic, consumerId, pushConsumer, classType)); }); //获取当前应用作为"顺序"类型消费者的相关信息 CreateConsumer <AbstractOrderConsumerService <object> >(assembly, type, ONSMessageType.ORDER, (onsConsumerFactoryProperty, topic, consumerId, classType) => { //实例化OrderConsumer OrderConsumer orderConsumer = ONSFactory.getInstance().createOrderConsumer(onsConsumerFactoryProperty); //实例化代理类ONSOrderConsumer return(new ONSOrderConsumer(topic, consumerId, orderConsumer, classType)); }); //获取当前应用作为"普通"类型消费者的相关信息 CreateConsumer <AbstractBaseConsumerService <object> >(assembly, type, ONSMessageType.BASE, (onsConsumerFactoryProperty, topic, consumerId, classType) => { //实例化PushConsumer PushConsumer pushConsumer = ONSFactory.getInstance().createPushConsumer(onsConsumerFactoryProperty); //实例化代理类ONSTransactionConsumer return(new ONSBaseConsumer(topic, consumerId, pushConsumer, classType)); }); } } } //*/ } } } //*/ }
/// <summary> /// 消费订阅 /// </summary> /// <param name="listen">消息监听处理</param> /// <param name="subExpression">标签</param> public void Start(MessageOrderListener listen, string subExpression = "*") { _consumer = ONSFactory.getInstance().createOrderConsumer(_factoryInfo); _consumer.subscribe(_factoryInfo.getPublishTopics(), subExpression, listen); _consumer.start(); }
public void InitializeOrderConsumer() { orderConsumer = ONSFactory.getInstance().createOrderConsumer(factoryInfo); }