public ONSTranProducer(string topic, string producerId, TransactionProducer transactionProducer) { this.Topic = topic; this.ProducerId = producerId; this.Type = ONSMessageType.TRAN.ToString().ToUpper();; _producer = transactionProducer; }
protected override IONSProducer InitilizeProducer(ONSFactoryProperty onsProducerFactoryProperty) { //实例化ONSLocalTransactionChecker ONSLocalTransactionChecker checker = new ONSLocalTransactionChecker(); //实例化TransactionProducer TransactionProducer transactionProducer = ONSFactory.getInstance().createTransactionProducer(onsProducerFactoryProperty, checker); //实例化代理类ONSTransactionProducer IONSProducer producer = new ONSTranProducer(this.Topic, this.Pid, transactionProducer); return(producer); }
public virtual TransactionProducer createTransactionProducer(ONSFactoryProperty factoryProperty, LocalTransactionChecker checker) { global::System.IntPtr cPtr = ONSClient4CPPPINVOKE.ONSFactoryAPI_createTransactionProducer(swigCPtr, ONSFactoryProperty.getCPtr(factoryProperty), LocalTransactionChecker.getCPtr(checker)); TransactionProducer ret = (cPtr == global::System.IntPtr.Zero) ? null : new TransactionProducer(cPtr, false); if (ONSClient4CPPPINVOKE.SWIGPendingException.Pending) { throw ONSClient4CPPPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
private void Form1_Load(object sender, EventArgs e) { factoryInfo = new ONSFactoryProperty(); factoryInfo.setFactoryProperty(ONSFactoryProperty.AccessKey, Ons_AccessKey); factoryInfo.setFactoryProperty(ONSFactoryProperty.SecretKey, Ons_SecretKey); factoryInfo.setFactoryProperty(ONSFactoryProperty.ProducerId, Ons_ProducerId); //factoryInfo.setFactoryProperty(ONSFactoryProperty.ConsumerId, Ons_ConsumerId); factoryInfo.setFactoryProperty(ONSFactoryProperty.PublishTopics, Ons_Topic); factoryInfo.setFactoryProperty(ONSFactoryProperty.LogPath, "D://log/rocketmq/producer"); LocalTransactionChecker myChecker = new MyLocalTransactionChecker(); producer = ONSFactory.getInstance().createTransactionProducer(factoryInfo, myChecker); producer.start(); }
public void InitializeOrderProducer() { myChecker = new MyLocalTransactionChecker(); transactionProducer = ONSFactory.getInstance().createTransactionProducer(factoryInfo, myChecker); transactionProducer.start(); }
/// <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)); }); } } } //*/ } } } //*/ }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TransactionProducer obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public TransactionProducerClient(string accessKeyId, string accessKeySecret, string producerId, Func <Message, TransactionStatus> checkFunc) : base(accessKeyId, accessKeySecret, producerId) { producer = ONSFactory.getInstance().createTransactionProducer(this.FactoryProperty, new ExtendedLocalTransactionChecker(checkFunc)); }