Windows ServerçšService Busãšã¯äœãã®ç°¡åãªèª¬æ
ããã¯ãWindowsäžã®Windows Azure Service Busã«éåžžã«è¿ãMicrosoft Service Busã®å®è£
ã§ãããAzureèªäœã¯å¿
èŠãããŸããã ã€ãŸããäžçš®ã®éåžžã«å¿«é©ã§é«åºŠãªã¿ã€ã€ã§ãã æšæºãã¥ãŒãšãã®é«åºŠãªãããã¯ãããã¯ã®äž¡æ¹ãæäŸã§ããåãã¡ãã»ãŒãžãè€æ°ã®ç°ãªããµãã¹ã¯ãªãã·ã§ã³ã«éä¿¡ã§ããŸãã å®éã«ã¯ãããã¯/ãµãã¹ã¯ãªãã·ã§ã³ã®ã¿ã«ééããããããããã«ã€ããŠã®ã¿èª¬æããŸãã
ã€ãŸããæ¶è²»è ã¯ãããã¯ã«æçš¿ãå ¬éããŸãã ãããã¯ã¯ãããããã¹ãŠã®ãµãã¹ã¯ãªãã·ã§ã³ã«è»¢éããŸãã 次ã«ããµãã¹ã¯ãªãã·ã§ã³ã¯ãã¡ãã»ãŒãžãå¿ èŠãã©ããã確èªããã«ãŒã«ã®ãªã¹ããšæ¯èŒããŸãïŒãã£ã«ã¿ãŒïŒã ãã¹ãŠã®é©åãªã¡ãã»ãŒãžã¯ããããã®åããµãã¹ã¯ãªãã·ã§ã³ã«ãµãã¹ã¯ã©ã€ãããŠãã顧客ã«éä¿¡ãããŸãã ããã«ãè€æ°ã®é¡§å®¢ãåããµãã¹ã¯ãªãã·ã§ã³ã«ãµãã¹ã¯ã©ã€ãããŠããå Žåããã®ãã¡ã®1人ã ããã¡ãã»ãŒãžãåä¿¡ããŸãã ãã¹ãŠãããªãæšæºã§ãã
ã€ãŸããæ¶è²»è ã¯ãããã¯ã«æçš¿ãå ¬éããŸãã ãããã¯ã¯ãããããã¹ãŠã®ãµãã¹ã¯ãªãã·ã§ã³ã«è»¢éããŸãã 次ã«ããµãã¹ã¯ãªãã·ã§ã³ã¯ãã¡ãã»ãŒãžãå¿ èŠãã©ããã確èªããã«ãŒã«ã®ãªã¹ããšæ¯èŒããŸãïŒãã£ã«ã¿ãŒïŒã ãã¹ãŠã®é©åãªã¡ãã»ãŒãžã¯ããããã®åããµãã¹ã¯ãªãã·ã§ã³ã«ãµãã¹ã¯ã©ã€ãããŠãã顧客ã«éä¿¡ãããŸãã ããã«ãè€æ°ã®é¡§å®¢ãåããµãã¹ã¯ãªãã·ã§ã³ã«ãµãã¹ã¯ã©ã€ãããŠããå Žåããã®ãã¡ã®1人ã ããã¡ãã»ãŒãžãåä¿¡ããŸãã ãã¹ãŠãããªãæšæºã§ãã
æåã®ã¹ããããšæåã®ã¬ãŒã
ãã®ããšã®äœ¿çšã¯ã©ãããå§ãŸããŸããïŒ ãã¡ãããã¡ãã»ãŒãžãéåä¿¡ããããšããŠããŸãã
泚æ ã以äžãéçç£ã³ãŒããèšèŒãããŠããŸããæ·»ä»ã³ãŒãã¯ãããã¹ãã®æ©èœèª¬æå³ãšããŠã®ã¿äœ¿çšããããšãç®çãšããŠããŸã
var messageFactory = MessagingFactory.CreateFromConnectionString(connectionString); var publisher = messageFactory.CreateTopicClient(topicName); var listener = messageFactory.CreateSubscriptionClient(topicName, subscriptionName); listener.OnMessage(message => Console.WriteLine($"Message received: {message.GetBody<string>()}")); var brokeredMessage = new BrokeredMessage("some test message"); publisher.Send(brokeredMessage);
ç°¡åã§ãã³ã³ãœãŒã«ã«ã¡ãã»ãŒãžã衚瀺ãããŸãã å€ãã®ã¡ãã»ãŒãžãå ¬éããŠãéåä¿¡ã«ãããæéã倧ãŸãã«æšå®ããŠã¿ãŸãããã
var stopwatch = new Stopwatch(); int messagesToSent = 200; int messagesProccessed = 0; listener.OnMessage(message => { Console.WriteLine($"Message received: {message.GetBody<string>()}"); messagesProccessed++; if (messagesProccessed == messagesToSent) { stopwatch.Stop(); Console.WriteLine($"Time passed: {stopwatch.Elapsed}"); } }); stopwatch.Start(); for (var i = 0; i < messagesToSent; i ++) { var brokeredMessage = new BrokeredMessage($"Message â{i}"); publisher.Send(brokeredMessage); }
ãã®ã³ãŒããå®è¡ãããšãå€ãããã©ã³ã®ã³ã³ãã¥ãŒã¿ãŒã§ã¯ãåŠçã«çŽ6ç§ããããŸãã
ãããã次ã®ã¹ãããã¯ãã°ãã°æåã®ã¬ãŒãã«ã€ãªãããŸãã å®éã«ã¯ããµãã¹ã¯ã©ã€ããŒã¯æ¬¡ã®2ã€ã®ã¢ãŒãã®ããããã§ã¡ãã»ãŒãžãåä¿¡ã§ããŸãã
- PeekLock-ã¡ãã»ãŒãžã¯åä¿¡ãããŸããããµãã¹ã¯ãªãã·ã§ã³ããåé€ããããããã¯ã®ã¿ãåä¿¡ããŸãã åé€ããããã«ã¯ãã¯ã©ã€ã¢ã³ãã¯CommitïŒïŒãåŒã³åºããŠåŠçã®æåãæ瀺çã«ç¢ºèªããå¿
èŠããããŸãã ãã以å€ã®å Žåãããã¯ã®æå¹æéãåãããã AbandonïŒïŒãåŒã³åºãããšã«ãããã¯ã©ã€ã¢ã³ãã¯ãã®ã¡ãã»ãŒãžãå床é
ä¿¡ããããšããŸãã
- ReceiveAndDelete-ã¡ãã»ãŒãžãåä¿¡ããããµãã¹ã¯ãªãã·ã§ã³ããããã«åé€ãããŸãã åŠçã倱æããå Žåããã®ã¡ãã»ãŒãžã¯åã³è¡šç€ºãããŸããã ãã ããããã¯ããã³ã°ããªãããã PeekLockãããå°ãéãåäœããŸãã
ããã©ã«ãã§ã¯ã messageFactory.CreateSubscriptionClientã¯PeekLockãªãã·ã§ã³ãäœæããŸãã ãããããã®éèªææ§ã®ãããã¯ã©ã€ã¢ã³ããåäœã¢ãŒãã®æ瀺çãªæ瀺ãªãã«äœæãããããšãå®éã«ã¯èŠãŸããã§ããã ãŸããããã¥ã¡ã³ãã«ãããšã PeekLockãæå®ãããŠããå Žåãã¡ãã»ãŒãžããšã«.CompleteïŒïŒãåŒã³åºãå¿ èŠããããŸãã ãããè©ŠããŠã¿ãŸãããïŒ
listener.OnMessage(message => { Console.WriteLine($"Message received: {message.GetBody<string>()}"); messagesProccessed++; if (messagesProccessed == messagesToSent) { stopwatch.Stop(); Console.WriteLine($"Time passed: {stopwatch.Elapsed}"); } message.Complete(); // , });
ãããŠãäºæããªãããšãèµ·ãããŸãã å®è¡ãã¹ããŒãããªããšããäºå®ã«ããããããããã¡ãã»ãŒãžçªå·Xãã®è¡ã¯å®è¡ãããŸããããã¹ãŠãéåžžã«ãã£ãããšçºçããŸãã ãããã®200ã®ã¡ãã»ãŒãžã¯ã6ç§ã§ã¯ãªãã4å9ç§ãããããŸããã ããã¯å€ãéãæ£åœåãããã®ã§ã¯ãããŸããã ããããã©ã€ããããžã§ã¯ãã®ã³ãŒãã§ãã®åé¡ãäžåºŠçºèŠããŸãããå°æ°ã®ã¡ãã»ãŒãžã«ã€ããŠã¯ãããã©ãŒãã³ã¹ã®äœäžã¯æããã§ã¯ãããŸããã§ããã
ãªããããèµ·ãã£ãŠããã®ã§ããïŒ çµå±ã®ãšãããäœããæ£ãããªãå Žåãå®è¡ãæåŸ ãããã§ããããïŒ å®éãåä»ã¯ããã§ãã ãŸã£ããæ確ãªçç±ã§ã¯ãªãããMicrosoftã¯ãããã®äŸå€ã«é¢ããæ å ±ãååŸããããã®æ¥µããŠæçœãªæ¹æ³ãäœæããŸããã
OnMessageã¡ãã»ãŒãžãµãã¹ã¯ãªãã·ã§ã³ã¡ãœããã¯ããªãã·ã§ã³ã®OnMessageOptionsãã©ã¡ãŒã¿ãŒãåãå ¥ããŸããããã«ããã ExceptionReceivedã€ãã³ãããµãã¹ã¯ã©ã€ãã§ããŸãã ã€ãŸããåããé ãããäŸå€ãã§ãã
var onMessageOptions = new OnMessageOptions(); onMessageOptions.ExceptionReceived += (sender, args) => Console.WriteLine($"Exception received: {args.Exception}"); listener.OnMessage(message => { Console.WriteLine($"Message received: {message.GetBody<string>()}"); messagesProccessed++; if (messagesProccessed == messagesToSent) { stopwatch.Stop(); Console.WriteLine($"Time passed: {stopwatch.Elapsed}"); } message.Complete(); }, onMessageOptions); // onMessageOptions
ãã®ã³ãŒããå®è¡ãããšã Microsoft.ServiceBus.Messaging.MessageLockLostExceptionãåã¡ãã»ãŒãžã§ã¹ããŒãããããšãããããŸãã
æå®ãããããã¯ã¯ç¡å¹ã§ãã 圌女ã¯æéåãã«ãªã£ãŠããããã¡ãã»ãŒãžãæ¢ã«ãã¥ãŒããåé€ãããŠããŸã.. TrackingIdïŒ54630ae4-6e4f-4979-8fc8-b66e5314079c_GAPC_BAPCãTimeStampïŒ08.24.2016 21:20:08
ãªããããèµ·ãã£ãŠããã®ã§ããïŒ onMessageOptionsã«ã¯ãã1ã€ã®ãã©ã¡ãŒã¿ãŒAutoCommitãããããã§ãã ãããŠãããã©ã«ãã¯trueã§ãã ãããã£ãŠãã¡ãã»ãŒãžã®ã©ã€ããµã€ã¯ã«ãç¬ç«ããŠå¶åŸ¡ããå Žåãæ£ããåäœããã«ã¯ããã®ãã£ãŒã«ããfalseã«èšå®ããå¿ èŠããããŸãã ãããè©ŠããŠã¿ãŸãããïŒ
var stopwatch = new Stopwatch(); int messagesToSent = 200; int messagesProccessed = 0; var onMessageOptions = new OnMessageOptions { AutoComplete = false // }; onMessageOptions.ExceptionReceived += (sender, args) => Console.WriteLine($"Exception received: {args.Exception}"); listener.OnMessage(message => { Console.WriteLine($"Message received: {message.GetBody<string>()}"); messagesProccessed++; if (messagesProccessed == messagesToSent) { stopwatch.Stop(); Console.WriteLine($"Time passed: {stopwatch.Elapsed}"); } message.Complete(); }, onMessageOptions); stopwatch.Start(); for (var i = 0; i < messagesToSent; i ++) { var brokeredMessage = new BrokeredMessage($"Message â{i}"); publisher.Send(brokeredMessage); }
åºæ¥äžããïŒå®è¡ãªããã¡ãã»ãŒãžåŠçã«ãããæéã¯ããã2.5ç§ã§ãã éåžžã®æäœã®ããã«èŠããŸãã
èŠçŽãããš ïŒ
- ã»ãšãã©ã®å Žåã onMessageOptions.ExceptionReceivedããµãã¹ã¯ã©ã€ãããå¿ èŠããããŸããããããªããšãã³ãŒãå ã®å€ãã®åé¡ã«æ°ä»ããªãå ŽåããããŸãã
- ããã©ã«ãã§ã¯ããµãŒãã¹ããŒã¹ã¯ã¡ãã»ãŒãžãã³ãããããããšããããšã«æ³šæããŠãã ããã ã»ãšãã©ã®å Žåããã®åäœã¯ãªãã«ããå¿ èŠããããŸãã
æœè±¡åãšã¬ãŒã2
å®çšŒåã³ãŒãã§ãèŠããã2çªç®ã®ãããã»ã©äžè¬çã§ã¯ãªãç¬éã¯ããµãã¹ã¯ã©ã€ããŒã®ã©ãããŒã®èª€ã£ãäœæã§ãã äžè¬çã«ããµãŒãã¹ããŒã¹ãæäœããå éšã«é ããŠããã¯ã©ã¹ãäœæããããšã¯è¯ãããšã§ãã ãããã埮åŠãªéãããããŸãã ãããè¡ããªãæ¹æ³ã®äŸã瀺ããŸãããå®éã«ã¯åæ§ã®ã³ãŒããè€æ°åèŠãããŠããŸãã
ãã®çš®é¡ã®ã¯ã©ã¹ã¯äœæãããŸãïŒ
class Listener : IListener { private readonly MessagingFactory _messageFactory; private readonly SubscriptionClient _client; public event Func<string, Task> OnReceivedAsync; public Listener(string connectionString, string topicName, string subscriptionName, ReceiveMode receiveMode) { _messageFactory = MessagingFactory.CreateFromConnectionString(connectionString); _client = _messageFactory.CreateSubscriptionClient(topicName, subscriptionName, receiveMode); var onMessageOptions = new OnMessageOptions { AutoComplete = false }; onMessageOptions.ExceptionReceived += (sender, args) => Console.WriteLine($"Exception received: {args.Exception}"); _client.OnMessageAsync(bm => OnReceivedAsync?.Invoke(bm.GetBody<string>()), onMessageOptions); } }
ããã«æ¬¡ã®ããã«äœ¿çšãããŸãïŒ
var messageFactory = MessagingFactory.CreateFromConnectionString(connectionString); var publisher = messageFactory.CreateTopicClient(topicName); int messagesToSent = 20; for (var i = 0; i < messagesToSent; i++) { var brokeredMessage = new BrokeredMessage($"Message â{i}"); publisher.Send(brokeredMessage); } var listener = new Listener(connectionString, topicName, subscriptionName, ReceiveMode.ReceiveAndDelete); listener.OnReceivedAsync += x => { Console.WriteLine($"Message received: {x}"); return Task.FromResult(true); };
ãã®ã³ãŒããå®è¡ãããšããã¹ãŠãæ©èœããŠããããã«èŠããŸãããæåã®ã¡ãã»ãŒãžã®ä»£ããã«ã NullReferenceExceptionïŒObject reference not set to object of instanceã ããšãããšã©ãŒã衚瀺ãããŸãã
ããã«ãonMessageOptions.ExceptionReceivedã«ãµãã¹ã¯ã©ã€ãããå Žåã«ã®ã¿ãšã©ãŒããã£ãããããŸãããããè¡ããªãå ŽåïŒããã³äœããã®çç±ã§é »ç¹ã«è¡ããªãå ŽåïŒãã³ãŒãåäœã®éæ¥çãã€éåžžã«ãããã«ãããã°ã«ãã£ãŠã®ã¿åé¡ãèŠã€ããããšãã§ããŸãã
ããã§äœãééã£ãŠããŸããïŒ çãã¯ããªãæçœã§ããããç§ãããã»ã©é »ç¹ã«äŒããªããã°ãããããèšåããªãã£ãã§ãããã ãªã¹ããŒæœè±¡åã³ã³ã¹ãã©ã¯ã¿ãŒã§_client.OnMessageAsyncãåŒã³åºããããšããµãã¹ã¯ã©ã€ããŒã¯æ¢ã«ã¡ãã»ãŒãžã®åä¿¡ãéå§ããŠããŸãã ãã®ããããããã®å€ãïŒã³ã³ã¹ãã©ã¯ã¿ãŒãšlistener.OnReceivedAsyncãžã®ãµãã¹ã¯ãªãã·ã§ã³ãã©ã®çšåºŠé¢ããŠãããã«å¿ããŠïŒã¯ã¹ãããããã空ã®OnReceivedAsyncïŒ.Invokeã«è©²åœã ãè«ççã«nullãè¿ããŸãããããã£ãŠã NullReferenceException ã
ãããã©ãããŸããïŒ æãç°¡åãªããšã¯ã次ã®ããã«ã€ã³ã¹ã¿ã³ã¹ã®äœæãšãµãã¹ã¯ãªãã·ã§ã³ãèšå®ããããšã§ãã
class Listener : IListener { private readonly MessagingFactory _messageFactory; private readonly SubscriptionClient _client; public Listener(string connectionString, string topicName, string subscriptionName, ReceiveMode receiveMode) { _messageFactory = MessagingFactory.CreateFromConnectionString(connectionString); _client = _messageFactory.CreateSubscriptionClient(topicName, subscriptionName, receiveMode); } public void Subscribe(Func<string, Task> handleMessage) { var onMessageOptions = new OnMessageOptions { AutoComplete = false }; onMessageOptions.ExceptionReceived += (sender, args) => Console.WriteLine($"Exception received: {args.Exception}"); _client.OnMessageAsync(bm => handleMessage(bm.GetBody<string>()), onMessageOptions); } }
ãããŠããã®ãããªãã®ããµãã¹ã¯ã©ã€ãããŸãïŒ
var listener = new Listener(connectionString, topicName, subscriptionName, ReceiveMode.ReceiveAndDelete); listener.Subscribe(x => { Console.WriteLine($"Message received: {x}"); return Task.FromResult(true); });
ã¯ã©ã¹ã®äœææã«ã¡ãã»ãŒãžã倱ãããããšã¯ãªããªããŸããã
èŠçŽãããš ïŒ
- onMessageOptions.ExceptionReceivedãžã®ãµãã¹ã¯ã©ã€ãã¯ãçŸåšãããé¢é£æ§ããããŸã
- client.OnMessageAsyncãåŒã³åºããçŽåŸã«ã¡ãã»ãŒãžã®åä¿¡ãéå§ãããããšãå¿ããªãã§ãã ãããæœè±¡åãèšèšãããšãã¯ãããèæ ®ããŠãã ããã
ãããçªå·3
ãµãã¹ã¯ã©ã€ããŒã«ã¯ãã°ãããCloseïŒïŒã¡ãœããããããŸãã ãããã圌ã®è¡åã¯å®å šã«äºæž¬å¯èœãªæšæž¬ã§ã¯ãããŸããã ããã§ãã®ãããªã³ãŒããå®è¡ããŠã¿ãŸããããã¡ãã»ãŒãžã®ååãéä¿¡ããåŸããã®CloseïŒïŒãåŒã³åºããå¥ã®ãµãã¹ã¯ã©ã€ããŒã€ã³ã¹ã¿ã³ã¹ãéããŠåŸåã®ã¡ãã»ãŒãžãåä¿¡ããŸãã
var messageFactory = MessagingFactory.CreateFromConnectionString(connectionString); var publisher = messageFactory.CreateTopicClient(topicName); var listener1 = messageFactory.CreateSubscriptionClient(topicName, subscriptionName, ReceiveMode.ReceiveAndDelete); var listener2 = messageFactory.CreateSubscriptionClient(topicName, subscriptionName, ReceiveMode.ReceiveAndDelete); int messagesToSent = 10; int messagesProccessed = 0; var onMessageOptions = new OnMessageOptions { AutoComplete = false }; onMessageOptions.ExceptionReceived += (sender, args) => Console.WriteLine($"Exception received: {args.Exception}"); listener1.OnMessage(message => { Console.WriteLine($"listener1: message received: {message.GetBody<string>()}, listener1 is closed: {listener1.IsClosed}"); messagesProccessed++; }, onMessageOptions); for (var i = 0; i < messagesToSent; i++) { var brokeredMessage = new BrokeredMessage($"Message â{i}"); publisher.Send(brokeredMessage); Thread.Sleep(50); if (i == 4) { Console.WriteLine("Closing listener1"); listener1.Close(); } } listener2.OnMessage(message => { Console.WriteLine($"listener2: message received : {message.GetBody<string>()}, listener2 is closed: {listener2.IsClosed}"); messagesProccessed++; }, onMessageOptions);
ããããã³ã³ãœãŒã«ã®çµæã¯æ¬¡ã®ããã«ãªããŸãã
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·0ãlistener1ã¯éããŠããŸãïŒFalse
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·1ãlistener1ã¯éããŠããŸãïŒFalse
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·2ãlistener1ãéããŠããïŒFalse
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžNo. 3ãlistener1ãéããŠããïŒFalse
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·4ãlistener1ãéããŠããïŒFalse
ãªã¹ããŒ1ãéãã
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·5ãlistener1ãéããŠããïŒTrue
listener2ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·6ãlistener2ã¯éããŠããŸãïŒFalse
listener2ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·7ãlistener2ã¯éããŠããŸãïŒFalse
listener2ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžNo. 8ãlistener2ã¯éããŠããŸãïŒFalse
listener2ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·9ãlistener2ã¯éããŠããŸãïŒFalse
æããã§ã¯ãªãã§ãããïŒ åãããšãè¡ããã ReceiveAndDeleteã§ã¯ãªãPeekLockåäœã¢ãŒãã®å Žåã.CompleteïŒïŒãSystem.OperationCanceledExceptionãã¹ããŒããããšãé€ããŠãçµæã¯åæ§ã«ãªããŸãïŒãã®ã¡ãã»ãŒãžã³ã°ãšã³ãã£ãã£ã¯æ¢ã«éããããäžæ¢ãããç Žæ£ãããŸãã ã ãŸããã¡ãã»ãŒãžãã³ãã©ã§ãšã©ãŒããã£ããããŠAbandonïŒïŒãæåã§å®è¡ãããšã AbandonïŒïŒèªäœããšã©ãŒãã¹ããŒããŸãã ãããŠããããã®ã¢ã¯ã·ã§ã³ã¯ã©ã¡ããæ®éã§ããã OnMessageOptionsã®äžã«é ããŠããŸããã
ãããŠã ReceedAndDeleteãšã¯å¯Ÿç §çã«ãæ¬ èœããã¡ãã»ãŒãžèªäœã¯ãåéä¿¡ãçºçãããšãã«åŒãç¶ãåŠçãããŸãã
å®å
šãªåºåãšã³ã³ãœãŒã«åºåãåããã³ãŒã
var messageFactory = MessagingFactory.CreateFromConnectionString(connectionString); var messageFactory1 = MessagingFactory.CreateFromConnectionString(connectionString); var messageFactory2 = MessagingFactory.CreateFromConnectionString(connectionString); var publisher = messageFactory.CreateTopicClient(topicName); var listener1 = messageFactory1.CreateSubscriptionClient(topicName, subscriptionName, ReceiveMode.PeekLock); var listener2 = messageFactory2.CreateSubscriptionClient(topicName, subscriptionName, ReceiveMode.PeekLock); int messagesToSent = 10; int messagesProccessed = 0; var onMessageOptions = new OnMessageOptions { AutoComplete = false }; onMessageOptions.ExceptionReceived += (sender, args) => Console.WriteLine($"Exception received: {args.Exception}"); listener1.OnMessage(message => { try { Console.WriteLine($"listener1: message received: {message.GetBody<string>()}, listener1 is closed: {listener1.IsClosed}"); messagesProccessed++; message.Complete(); } catch (Exception ex1) { Console.WriteLine($"listener1 Complete() exception: {ex1.Message}"); try { message.Abandon(); } catch (Exception ex2) { Console.WriteLine($"listener1 Abandon() exception: {ex2.Message}"); } } }, onMessageOptions); for (var i = 0; i < messagesToSent; i++) { var brokeredMessage = new BrokeredMessage($"Message â{i}"); publisher.Send(brokeredMessage); Thread.Sleep(50); if (i == 4) { Console.WriteLine("Closing listener1"); listener1.Close(); } } listener2.OnMessage(message => { Console.WriteLine($"listener2: message received : {message.GetBody<string>()}, listener2 is closed: {listener2.IsClosed}"); messagesProccessed++; message.Complete(); }, onMessageOptions);
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·0ãlistener1ã¯éããŠããŸãïŒFalse
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·1ãlistener1ã¯éããŠããŸãïŒFalse
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·2ãlistener1ãéããŠããïŒFalse
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžNo. 3ãlistener1ãéããŠããïŒFalse
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·4ãlistener1ãéããŠããïŒFalse
ãªã¹ããŒ1ãéãã
listener1ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·5ãlistener1ãéããŠããïŒTrue
listener1 CompleteïŒïŒäŸå€ïŒãã®ã¡ãã»ãŒãžã³ã°ãšã³ãã£ãã£ã¯æ¢ã«éããããŠããããäžæ¢ãããŠããããç Žæ£ãããŠããŸãã
listener1 AbandonïŒïŒäŸå€ïŒãã®ã¡ãã»ãŒãžã³ã°ãšã³ãã£ãã£ã¯æ¢ã«éããããŠããããäžæ¢ãããŠããããç Žæ£ãããŠããŸãã
listener2ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·6ãlistener2ã¯éããŠããŸãïŒFalse
listener2ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·7ãlistener2ã¯éããŠããŸãïŒFalse
listener2ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžNo. 8ãlistener2ã¯éããŠããŸãïŒFalse
listener2ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·9ãlistener2ã¯éããŠããŸãïŒFalse
listener2ïŒåä¿¡ããã¡ãã»ãŒãžïŒã¡ãã»ãŒãžçªå·5ãlistener2ã¯éããŠããŸãïŒFalse
ããã§äœãããã®ããã©ããã£ãŠçããã®ãïŒ ããã«ã€ããŠã¯ãã³ãŒãã§ãããèŠããŠèæ ®ããå¿ èŠããããŸãã ãã¹ãŠãç¥ã£ãŠããstackoverflowã¯ããã®åäœã«å¯ŸåŠããã®ã«ååãªãªãã·ã§ã³ãæäŸããŸãã ããšãã°ãå¿ èŠã«å¿ããŠããµãã¹ã¯ã©ã€ããŒãéããã®ãšåæã«messageFactory.CloseïŒïŒãåŒã³åºãããšãã§ããŸãã ãŸãã¯ããµãã¹ã¯ã©ã€ããŒãifïŒlistener.IsClosedïŒ{/ *** /}ãªã©ã®ããã«éããããŠããå Žåã¯ãã³ãã©ãŒããã§ãã¯ã€ã³ããŸãã
èŠçŽãããš ïŒ
- ãµãŒãã¹ããŒã¹ããã®ãã¹ãŠã®ekspressnyãonMessageOptions.ExceptionReceivedã§ã®ã¿å°çããããã§ã¯ãããŸããã
- ãµãã¹ã¯ã©ã€ããŒãšã®äœæ¥ãå®äºãããšãã CloseïŒïŒã¡ãœããã®æ©èœãèæ ®ããå¿ èŠããããŸã
ãããã«
äžè¬ã«ãWindows Serverçšã®Service Busã¯éåžžã«åªããæ©èœã§ãããé©åã«æ©èœããŸãããæåã®ããã€ãã®ããããªããšã«ã¯ããããã®è¡ãæµããŸãã ãã®èšäºã«èšèŒãããŠãããã€ã³ãã誰ãã«åœ¹ç«ã€ããšã蚌æãã圌ãèªèº«ã®ã³ãŒã³ãè©°ã蟌ãããšããæãããšãé¡ã£ãŠããŸãã