static void Main(string[] args)
        {
            DDM_CHANNEL_DIRECTION direction = DDM_CHANNEL_DIRECTION.RECEIVER;

            SmartDataDistribution dataDistribution = new SmartDataDistribution();

            dataDistribution.LoggingEvent += DataDistribution_LoggingEvent;
#if USE_KAFKA
            KafkaConfiguration conf = null;
#else
            OpenDDSConfiguration conf = null;
#endif
            OPERATION_RESULT hRes = OPERATION_RESULT.DDM_NO_ERROR_CONDITION;

            if (args.Length == 0)
            {
#if USE_KAFKA
                conf = new KafkaConfiguration()
                {
                };
#else
                conf = new OpenDDSConfiguration()
                {
                    OpenDDSArgs = new OpenDDSConfiguration.OpenDDSArgsConfiguration()
                    {
                        DCPSConfigFile          = "dds_tcp_conf.ini",
                        DCPSTransportDebugLevel = 10,
                    },
                    DCPSInfoRepo = new OpenDDSConfiguration.DCPSInfoRepoConfiguration()
                    {
                        Autostart       = direction.HasFlag(DDM_CHANNEL_DIRECTION.RECEIVER), // start only on receiver
                        Monitor         = true,
                        Resurrect       = true,
                        PersistenceFile = "persistance.file",
                        ORBEndpoint     = "iiop://localhost:12345",
                    },
                    DomainParticipantQos = new DomainParticipantQosConfiguration()
                    {
                        EntityFactoryQosPolicy = new EntityFactoryQosPolicyConfiguration()
                        {
                            AutoenableCreatedEntities = true
                        },
                        PropertyQosPolicy = new PropertyQosPolicyConfiguration()
                        {
                            DDSSEC_PROP_IDENTITY_CA      = new PropertyQosPolicyConfiguration.Property("1"),
                            DDSSEC_PROP_IDENTITY_CERT    = new PropertyQosPolicyConfiguration.Property("2"),
                            DDSSEC_PROP_IDENTITY_PRIVKEY = new PropertyQosPolicyConfiguration.Property("3"),
                            DDSSEC_PROP_PERM_CA          = new PropertyQosPolicyConfiguration.Property("4"),
                            DDSSEC_PROP_PERM_DOC         = new PropertyQosPolicyConfiguration.Property("5"),
                            DDSSEC_PROP_PERM_GOV_DOC     = new PropertyQosPolicyConfiguration.Property("6", true),
                        }
                    }
                };
#endif
                hRes = dataDistribution.Initialize(conf);
            }
            else
            {
                hRes = dataDistribution.Initialize(args[0]);
            }

            if (hRes.Failed)
            {
                Console.WriteLine("Error in configuration.");
                Console.ReadKey();
                return;
            }

            if (!dataDistribution.Start(uint.MaxValue))
            {
                Console.ReadKey();
                return;
            }
#if USE_KAFKA
            KafkaChannelConfiguration channelConf = new KafkaChannelConfiguration(conf)
            {
                BootstrapBrokers = "206.189.214.143:9093",
                ClientId         = "myTest",
                GroupId          = "myTest",
            };
#else
            OpenDDSChannelConfiguration channelConf = new OpenDDSChannelConfiguration(conf)
            {
                TopicQos = new TopicQosConfiguration()
                {
                    TopicDataQosPolicy = new TopicDataQosPolicyConfiguration()
                    {
                        Value = new byte[] { 100, 23 }
                    },
                    DurabilityQosPolicy = new DurabilityQosPolicyConfiguration()
                    {
                        Kind = DurabilityQosPolicyConfiguration.DurabilityQosPolicyKind.TRANSIENT_DURABILITY_QOS
                    }
                },
                SubscriberQos = new SubscriberQosConfiguration()
                {
                    EntityFactoryQosPolicy = new EntityFactoryQosPolicyConfiguration()
                    {
                        AutoenableCreatedEntities = true
                    }
                }
            };
#endif
            SmartDataDistributionChannel testChannel = dataDistribution.CreateSmartChannel <SmartDataDistributionChannel>("test2", channelConf);
            testChannel.DataAvailable    += TestChannel_DataAvailable;
            testChannel.ConditionOrError += TestChannel_ConditionOrError;

            Console.WriteLine("After CreateSmartChannel...\n");

            testChannel.StartChannel(uint.MaxValue);

            uint counter = 100;
            int  pid     = Process.GetCurrentProcess().Id;
            var  str     = string.Format("{0:10}", pid);

            Console.WriteLine("Starting operations...\n");
            while (true)
            {
                if (direction.HasFlag(DDM_CHANNEL_DIRECTION.TRANSMITTER))
                {
                    if (testChannel.WriteOnChannel(str).Succeeded)
                    {
                        str = string.Format("{0:10}", counter++);
                        if ((counter % THRESHOLD) == 0)
                        {
                            string key = string.Format("SendData Reached {0}", counter);
                            testChannel.WriteOnChannel(key, str);
                            Console.WriteLine(key);
                        }
                    }
                }
                Thread.Sleep(1000);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get the right configuration for the module
        /// Should be managed in setting window
        /// </summary>
        /// <param name="cm"></param>
        /// <returns></returns>
        private CommonConfiguration Configuration(CommunicationModule cm)
        {
            CommonConfiguration conf = null;

            switch (cm.TransportType)
            {
            case TransportEnum.OPEN_DDS:
                OpenDDSConfiguration oddsConfiguration = new OpenDDSConfiguration()
                {
                    OpenDDSArgs = new OpenDDSConfiguration.OpenDDSArgsConfiguration()
                    {
                        DCPSConfigFile          = "dds_tcp_conf.ini",
                        DCPSTransportDebugLevel = 10,
                    },
                    DCPSInfoRepo = new OpenDDSConfiguration.DCPSInfoRepoConfiguration()
                    {
                        Autostart   = StartServer,
                        ORBEndpoint = "iiop://localhost:12345",
                    }
                };
                OpenDDSChannelConfiguration oddsChannelConf = new OpenDDSChannelConfiguration(oddsConfiguration)
                {
                    TopicQos = new TopicQosConfiguration()
                    {
                        TopicDataQosPolicy = new TopicDataQosPolicyConfiguration()
                        {
                            Value = new byte[] { 100, 23 }
                        },
                        DurabilityQosPolicy = new DurabilityQosPolicyConfiguration()
                        {
                            Kind = DurabilityQosPolicyConfiguration.DurabilityQosPolicyKind.PERSISTENT_DURABILITY_QOS
                        },
                        DurabilityServiceQosPolicy = new DurabilityServiceQosPolicyConfiguration()
                        {
                            HistoryDepth = 100,
                            Kind         = DurabilityServiceQosPolicyConfiguration.HistoryQosPolicyKind.KEEP_ALL_HISTORY_QOS,
                        },
                        ReliabilityQosPolicy = new ReliabilityQosPolicyConfiguration()
                        {
                            Kind = ReliabilityQosPolicyConfiguration.ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS
                        }
                    },
                    SubscriberQos = new SubscriberQosConfiguration()
                    {
                        EntityFactoryQosPolicy = new EntityFactoryQosPolicyConfiguration()
                        {
                            AutoenableCreatedEntities = true
                        },
                    }
                };
                conf = oddsChannelConf;
                break;

            case TransportEnum.KAFKA:
                KafkaConfiguration kConfiguration = new KafkaConfiguration()
                {
                };
                KafkaChannelConfiguration kChannelConfiguration = new KafkaChannelConfiguration(kConfiguration)
                {
                    AutoOffsetReset  = (cm.ChannelName == "users") ? AutoOffsetResetType.beginning : AutoOffsetResetType.latest,
                    InitialOffset    = (cm.ChannelName == "users") ? InitialOffsetTypes.Beginning : InitialOffsetTypes.Stored,
                    ClientId         = "chat" + cm.ChannelName + cm.Id.ToString(),
                    GroupId          = "chatGrp" + cm.Id.ToString(),
                    BootstrapBrokers = "206.189.214.143:9093",
                };
                conf = kChannelConfiguration;
                break;
            }
            return(conf);
        }