private void CloseSender() { if (_messageSender == null) { return; } if (_messageSender.IsClosed) { _messageSender = null; return; } try { _messageSender .CloseAsync() .ContinueWith(task => { var ex = task.Exception; if (ex != null) { InternalLogger.Error("Exception closing MessageSender [{0}]", ex); } _messageSender = null; }); } catch (Exception ex) { InternalLogger.Error("Couldn't close MessageSender [{0}]", ex); } }
public SendAsyncResult(ServiceBusOutputChannel outputChannel, Message message, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { bool flag; bool flag1; this.outputChannel = outputChannel; outputChannel.AddHeadersTo(message); outputChannel.TraceSendingMessage(message); BrokeredMessage brokerMessage = null; try { brokerMessage = outputChannel.ConvertToBrokerMessage(message, out this.bufferToReturn); Microsoft.ServiceBus.Messaging.MessageSender messageSender = outputChannel.MessageSender; BrokeredMessage[] brokeredMessageArray = new BrokeredMessage[] { brokerMessage }; if (base.SyncContinue(messageSender.BeginSend(brokeredMessageArray, timeout, base.PrepareAsyncCompletion(ServiceBusOutputChannel.SendAsyncResult.onSendComplete), this))) { base.Complete(true); } } catch (MessagingException messagingException) { CommunicationException communicationException = MessagingExceptionHelper.ConvertToCommunicationException(messagingException, out flag); if (flag) { this.outputChannel.Fault(); } throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsError(communicationException, null); } catch (OperationCanceledException operationCanceledException1) { OperationCanceledException operationCanceledException = operationCanceledException1; MessagingException innerException = operationCanceledException.InnerException as MessagingException; if (innerException != null) { MessagingExceptionHelper.ConvertToCommunicationException(innerException, out flag1); if (flag1) { this.outputChannel.Fault(); } } ExceptionTrace exception = Microsoft.ServiceBus.Messaging.FxTrace.Exception; string entityClosedOrAborted = SRClient.EntityClosedOrAborted; Exception innerException1 = operationCanceledException.InnerException; if (innerException1 == null) { innerException1 = operationCanceledException; } throw exception.AsError(new CommunicationObjectAbortedException(entityClosedOrAborted, innerException1), null); } catch (Exception exception1) { if (this.bufferToReturn != null) { this.outputChannel.ChannelFactory.BufferManager.ReturnBuffer(this.bufferToReturn); } throw; } }
public void nsm_mf_and_topic() { var tp = TestConfigFactory.CreateTokenProvider(); var mf = TestConfigFactory.CreateMessagingFactory(tp); desc = new QueueDescriptionImpl("to-be-drained"); nm = TestConfigFactory.CreateNamespaceManager(mf, tp); client = mf.NewSenderAsync(nm, desc).Result; // sanity checks; I can now place a message in the queue client.Send(new BrokeredMessage(new A("My Contents", new byte[] {1, 2, 3}))); }
public void nsm_mf_and_topic() { var tp = TestConfigFactory.CreateTokenProvider(); var mf = TestConfigFactory.CreateMessagingFactory(tp); desc = new QueueDescriptionImpl("to-be-drained"); nm = TestConfigFactory.CreateNamespaceManager(mf, tp); client = mf.NewSenderAsync(nm, desc).Result; // sanity checks; I can now place a message in the queue client.Send(new BrokeredMessage(new A("My Contents", new byte[] { 1, 2, 3 }))); }
public static new Microsoft.ServiceBus.Messaging.MessageSender End(IAsyncResult result) { Microsoft.ServiceBus.Messaging.MessageSender messageSender; try { messageSender = AsyncResult.End <ServiceBusOutputChannel.OpenMessagingFactoryAndMessageSenderAsyncResult>(result).messageSender; } catch (MessagingException messagingException1) { MessagingException messagingException = messagingException1; throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsError(MessagingExceptionHelper.ConvertToCommunicationException(messagingException), null); } return(messageSender); }
private async Task CreateClient() { if (_isClosing) { return; } if (_messagingFactory == null || _messagingFactory.IsClosed) { _messagingFactory = await Task <MSSB.MessagingFactory> .Factory .StartNew(() => _isClosing?null : string.IsNullOrEmpty(ConnectionString) ?MSSB.MessagingFactory.Create() : MSSB.MessagingFactory.CreateFromConnectionString(ConnectionString)); } if (_messagingFactory != null) { if (_messageSender == null || _messageSender.IsClosed) { _messageSender = await _messagingFactory.CreateMessageSenderAsync(TopicOrQueueName); } } }