public GlobalStreamThread GetGlobalStreamThread()
        {
            var stateManager = new GlobalStateManager(topology, adminClient, configuration);
            var context      = new GlobalProcessorContext(configuration, stateManager);

            stateManager.SetGlobalProcessorContext(context);
            var globalStateUpdateTask = new GlobalStateUpdateTask(stateManager, topology, context);

            return(new GlobalStreamThread(threadClientId, globalConsumer, configuration, globalStateUpdateTask));
        }
Exemple #2
0
        public void TestGlobalProcessorContextStateDir()
        {
            var streamConfig = new StreamConfig();

            streamConfig.ApplicationId = "test-global-processor-context";
            streamConfig.StateDir      = Path.Combine(".", Guid.NewGuid().ToString());

            var context = new GlobalProcessorContext(streamConfig,
                                                     new GlobalStateManager(null, ProcessorTopology.EMPTY, null, null),
                                                     new StreamMetricsRegistry());

            Assert.AreEqual(Path.Combine(streamConfig.StateDir, streamConfig.ApplicationId, "global"),
                            context.StateDir);
        }
Exemple #3
0
        public TaskSynchronousTopologyDriver(string clientId, InternalTopologyBuilder topologyBuilder,
                                             IStreamConfig configuration, IStreamConfig topicConfiguration, IKafkaSupplier supplier,
                                             CancellationToken token)
        {
            this.configuration          = configuration;
            this.configuration.ClientId = clientId;
            this.topicConfiguration     = topicConfiguration;
            metricsRegistry             = new StreamMetricsRegistry(clientId, MetricsRecordingLevel.DEBUG);

            this.token    = token;
            builder       = topologyBuilder;
            this.supplier = supplier ?? new SyncKafkaSupplier();
            this.supplier.MetricsRegistry = metricsRegistry;
            producer = this.supplier.GetProducer(configuration.ToProducerConfig()) as SyncProducer;

            foreach (var sourceTopic in builder
                     .GetSourceTopics())
            {
                var part   = new TopicPartition(sourceTopic, 0);
                var taskId = builder.GetTaskIdFromPartition(part);
                if (partitionsByTaskId.ContainsKey(taskId))
                {
                    partitionsByTaskId[taskId].Add(part);
                }
                else
                {
                    partitionsByTaskId.Add(taskId, new List <TopicPartition> {
                        part
                    });
                }
            }

            ProcessorTopology globalTaskTopology = topologyBuilder.BuildGlobalStateTopology();

            hasGlobalTopology = globalTaskTopology != null;
            if (hasGlobalTopology)
            {
                var globalConsumer =
                    this.supplier.GetGlobalConsumer(configuration.ToGlobalConsumerConfig($"{clientId}-global-consumer"));
                var adminClient  = this.supplier.GetAdmin(configuration.ToAdminConfig($"{clientId}-admin"));
                var stateManager =
                    new GlobalStateManager(globalConsumer, globalTaskTopology, adminClient, configuration);
                globalProcessorContext = new GlobalProcessorContext(configuration, stateManager, metricsRegistry);
                stateManager.SetGlobalProcessorContext(globalProcessorContext);
                globalTask = new GlobalStateUpdateTask(stateManager, globalTaskTopology, globalProcessorContext);

                globalTask.Initialize();
            }
        }
Exemple #4
0
        public void TestGlobalProcessorContextTaskId()
        {
            var streamConfig = new StreamConfig();

            streamConfig.ApplicationId = "test-global-processor-context";
            streamConfig.StateDir      = Path.Combine(".", Guid.NewGuid().ToString());

            var context = new GlobalProcessorContext(streamConfig,
                                                     new GlobalStateManager(null, ProcessorTopology.EMPTY, null, null),
                                                     new StreamMetricsRegistry());

            Assert.AreEqual(new TaskId {
                Id = -1, Partition = -1
            }, context.Id);
            Assert.IsNull(context.Task);
        }