Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
181 lines (155 loc) · 9.19 KB

File metadata and controls

181 lines (155 loc) · 9.19 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using EQueue.Broker;
using EQueue.Clients.Consumers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IFramework.Infrastructure;
using IFramework.Message;
using IFramework.MessageQueue.EQueue;
using IFramework.Event;
using IFramework.Command;
using Microsoft.Practices.Unity;
using System.Threading.Tasks;
using Sample.Command;
using System.Threading;
using IFramework.Config;
using IFramework.Log4Net;
using IFramework.Infrastructure.Logging;
using EQueue.Clients.Producers;
using ECommon.Scheduling;
using ECommon.Components;
namespace EQueueTest
{
public class Program
{
static ICommandBus commandBus;
static ILogger _logger;
static void Main(string[] args)
{
try
{
Configuration.Instance.UseLog4Net()
.InitliaizeEQueue()
.CommandHandlerProviderBuild(null, "CommandHandlers");
var consumerSetting = new ConsumerSetting();
consumerSetting.MessageHandleMode = MessageHandleMode.Sequential;
consumerSetting.BrokerPort = 5001;
var producerSetting = new ProducerSetting();
var producerPort = producerSetting.BrokerPort = 5000;
var eventHandlerProvider = IoCFactory.Resolve<IHandlerProvider>("AsyncDomainEventSubscriber");
IMessageConsumer domainEventSubscriber = new DomainEventSubscriber("domainEventSubscriber1",
consumerSetting,
"DomainEventSubscriber",
"domainevent",
eventHandlerProvider);
domainEventSubscriber.Start();
IoCFactory.Instance.CurrentContainer.RegisterInstance("DomainEventConsumer", domainEventSubscriber);
IEventPublisher eventPublisher = new EventPublisher("EventPublisher", "domainevent",
producerSetting);
IoCFactory.Instance.CurrentContainer.RegisterInstance(typeof(IEventPublisher),
eventPublisher,
new ContainerControlledLifetimeManager());
var commandHandlerProvider = IoCFactory.Resolve<ICommandHandlerProvider>();
var commandConsumer1 = new CommandConsumer("consumer1", consumerSetting,
"CommandConsumerGroup",
"Command",
consumerSetting.BrokerAddress,
producerPort,
commandHandlerProvider);
var commandConsumer2 = new CommandConsumer("consumer2", consumerSetting,
"CommandConsumerGroup",
"Command",
consumerSetting.BrokerAddress,
producerPort,
commandHandlerProvider);
var commandConsumer3 = new CommandConsumer("consumer3", consumerSetting,
"CommandConsumerGroup",
"Command",
consumerSetting.BrokerAddress,
producerPort,
commandHandlerProvider);
var commandConsumer4 = new CommandConsumer("consumer4", consumerSetting,
"CommandConsumerGroup",
"Command",
consumerSetting.BrokerAddress,
producerPort,
commandHandlerProvider);
CommandConsumer.CommandConsumers.Add(commandConsumer1);
CommandConsumer.CommandConsumers.Add(commandConsumer2);
CommandConsumer.CommandConsumers.Add(commandConsumer3);
CommandConsumer.CommandConsumers.Add(commandConsumer4);
commandConsumer1.Start();
commandConsumer2.Start();
commandConsumer3.Start();
commandConsumer4.Start();
commandBus = new CommandBus("CommandBus",
commandHandlerProvider,
IoCFactory.Resolve<ILinearCommandManager>(),
consumerSetting.BrokerAddress,
producerPort,
consumerSetting,
"CommandBus",
"Reply",
"Command",
true);
IoCFactory.Instance.CurrentContainer.RegisterInstance(typeof(ICommandBus),
commandBus,
new ContainerControlledLifetimeManager());
commandBus.Start();
//Below to wait for consumer balance.
var scheduleService = ObjectContainer.Resolve<IScheduleService>();
var waitHandle = new ManualResetEvent(false);
var taskId = scheduleService.ScheduleTask("consumer logs", () =>
{
var bAllocatedQueueIds = (commandBus as CommandBus).Consumer.GetCurrentQueues().Select(x => x.QueueId);
var c1AllocatedQueueIds = commandConsumer1.Consumer.GetCurrentQueues().Select(x => x.QueueId);
var c2AllocatedQueueIds = commandConsumer2.Consumer.GetCurrentQueues().Select(x => x.QueueId);
var c3AllocatedQueueIds = commandConsumer3.Consumer.GetCurrentQueues().Select(x => x.QueueId);
var c4AllocatedQueueIds = commandConsumer4.Consumer.GetCurrentQueues().Select(x => x.QueueId);
var eAllocatedQueueIds = (domainEventSubscriber as DomainEventSubscriber).Consumer.GetCurrentQueues().Select(x => x.QueueId);
Console.WriteLine(string.Format("Consumer message queue allocation result:bus:{0}, eventSubscriber:{1} c1:{2}, c2:{3}, c3:{4}, c4:{5}",
string.Join(",", bAllocatedQueueIds),
string.Join(",", eAllocatedQueueIds),
string.Join(",", c1AllocatedQueueIds),
string.Join(",", c2AllocatedQueueIds),
string.Join(",", c3AllocatedQueueIds),
string.Join(",", c4AllocatedQueueIds)));
if (eAllocatedQueueIds.Count() == 4
&& bAllocatedQueueIds.Count() == 4
&& c1AllocatedQueueIds.Count() == 1
&& c2AllocatedQueueIds.Count() == 1
&& c3AllocatedQueueIds.Count() == 1
&& c4AllocatedQueueIds.Count() == 1)
{
waitHandle.Set();
}
}, 1000, 1000);
waitHandle.WaitOne();
scheduleService.ShutdownTask(taskId);
var worker = new Worker(commandBus);
worker.StartTest(100);
while (true)
{
Console.WriteLine(CommandConsumer.GetConsumersStatus());
Console.WriteLine(domainEventSubscriber.GetStatus());
Console.WriteLine("please input batch count and rerun another test:");
var input = Console.ReadLine();
var batchCount = 0;
if (int.TryParse(input, out batchCount))
{
worker.StartTest(batchCount);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.GetBaseException().Message, ex);
}
finally
{
Console.Read();
}
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.