/// <summary> /// Sends the with return. /// </summary> /// <param name="executeTimeout">The execute timeout.</param> /// <param name="endpoint">The endpoint.</param> /// <param name="messages">The messages.</param> /// <returns></returns> public override int SendWithReturn(int executeTimeout, IServiceBusEndpoint endpoint, params object[] messages) { if (messages == null || messages.Length == 0 || messages[0] == null) { throw new ArgumentNullException("messages", "Please include at least one message."); } IAsyncResult asyncResult; try { if (endpoint == null) { asyncResult = Bus.Send(NServiceBusTransport.Wrap(messages)).Register(state => { }, null); } if (endpoint != ServiceBus.SelfEndpoint) { asyncResult = Bus.Send(NServiceBusTransport.Cast(endpoint), NServiceBusTransport.Wrap(messages)).Register(state => { }, null); } else { throw new NotSupportedException(); } } catch (Exception ex) { throw new ServiceBusMessageException(messages[0].GetType(), ex); } if (!asyncResult.AsyncWaitHandle.WaitOne(executeTimeout)) { throw new TimeoutException(); } return(((CompletionResult)asyncResult.AsyncState).ErrorCode); }
/// <summary> /// Subscribes the specified message type. /// </summary> /// <param name="messageType">Type of the message.</param> /// <param name="predicate">The predicate.</param> public override void Subscribe(Type messageType, Predicate <object> predicate) { if (messageType == null) { throw new ArgumentNullException("messageType"); } try { if (predicate == null) { Bus.Subscribe(NServiceBusTransport.Wrap(messageType)); } else { Bus.Subscribe(NServiceBusTransport.Wrap(messageType), #if !CLR4 NServiceBusTransport.Cast(predicate) #else predicate #endif ); } } catch (Exception ex) { throw new ServiceBusMessageException(messageType, ex); } }
/// <summary> /// Publishes the specified messages. /// </summary> /// <param name="messages">The messages.</param> public virtual void Publish(params object[] messages) { if (messages == null || messages.Length == 0 || messages[0] == null) { throw new ArgumentNullException("messages"); } try { Bus.Publish(NServiceBusTransport.Cast(messages)); } catch (Exception ex) { throw new ServiceBusMessageException(messages[0].GetType(), ex); } }
/// <summary> /// Replies the specified messages. /// </summary> /// <param name="messages">The messages.</param> public virtual void Reply(params object[] messages) { if (messages == null || messages.Length == 0 || messages[0] == null) { throw new ArgumentNullException("messages", "Please include at least one message."); } try { Bus.Reply(NServiceBusTransport.Cast(messages)); } catch (Exception ex) { throw new ServiceBusMessageException(messages[0].GetType(), ex); } }
/// <summary> /// Sends the specified endpoint. /// </summary> /// <param name="endpoint">The endpoint.</param> /// <param name="messages">The messages.</param> /// <returns></returns> public override IServiceBusCallback Send(IServiceBusEndpoint endpoint, params object[] messages) { if (messages == null || messages.Length == 0 || messages[0] == null) { throw new ArgumentNullException("messages", "Please include at least one message."); } try { if (endpoint == null) { Bus.Send(NServiceBusTransport.Wrap(messages)); } else if (endpoint != ServiceBus.SelfEndpoint) { Bus.Send(NServiceBusTransport.Cast(endpoint), NServiceBusTransport.Wrap(messages)); } else { Bus.SendLocal(NServiceBusTransport.Wrap(messages)); } } catch (Exception ex) { throw new ServiceBusMessageException(messages[0].GetType(), ex); } return(null); }