internal StompClient( IStompFrameReader reader, IStompFrameWriter writer, TimeSpan? retryInterval = null, bool cascadeDispose = false, bool useRandomNumberGenerator = false) { if(reader.ProtocolVersion != writer.ProtocolVersion) throw new ArgumentException("Reader and writer MUST use the same protocol version."); _cascadeDispose = cascadeDispose; _reader = reader; _writer = writer; _frameObservable = new StompFrameObservable(reader); _frameWriter = new StompFrameWriterWithConfirmation(writer, _frameObservable, retryInterval); if (!useRandomNumberGenerator) { _receiptNumberGenerator = new SequenceNumberGenerator(); _subscriptionNumberGenerator = new SequenceNumberGenerator(); _transactionNumberGenerator = new SequenceNumberGenerator(); } else { _receiptNumberGenerator = new RandomSequenceNumberGenerator(); _subscriptionNumberGenerator = _receiptNumberGenerator; _transactionNumberGenerator = _receiptNumberGenerator; } }
internal StompClient( IStompFrameReader reader, IStompFrameWriter writer, TimeSpan?retryInterval = null, bool cascadeDispose = false, bool useRandomNumberGenerator = false) { if (reader.ProtocolVersion != writer.ProtocolVersion) { throw new ArgumentException("Reader and writer MUST use the same protocol version."); } _cascadeDispose = cascadeDispose; _reader = reader; _writer = writer; _frameObservable = new StompFrameObservable(reader); _frameWriter = new StompFrameWriterWithConfirmation(writer, _frameObservable, retryInterval); if (!useRandomNumberGenerator) { _receiptNumberGenerator = new SequenceNumberGenerator(); _subscriptionNumberGenerator = new SequenceNumberGenerator(); _transactionNumberGenerator = new SequenceNumberGenerator(); } else { _receiptNumberGenerator = new RandomSequenceNumberGenerator(); _subscriptionNumberGenerator = _receiptNumberGenerator; _transactionNumberGenerator = _receiptNumberGenerator; } }
public static Task WriteDisconnectAsync( this IStompFrameWriter writer, string receipt = null, IEnumerable <KeyValuePair <string, string> > extraHeaders = null, CancellationToken?cancellationToken = null) { CancellationToken cancelToken = cancellationToken ?? CancellationToken.None; Frame frame = StompFrameFactory.CreateDisconnect(receipt, extraHeaders); return(writer.WriteAsync(frame, cancelToken)); }
public static Task WriteSubscribeAsync( this IStompFrameWriter writer, string destination, string id, string receipt = null, string ack = null, IEnumerable <KeyValuePair <string, string> > extraHeaders = null, CancellationToken?cancellationToken = null) { CancellationToken cancelToken = cancellationToken ?? CancellationToken.None; Frame frame = StompFrameFactory.CreateSubscribe(destination, id, receipt, ack, extraHeaders); return(writer.WriteAsync(frame, cancelToken)); }
public static Task WriteSendAsync( this IStompFrameWriter writer, string destination, string body, string receipt = null, string transaction = null, IEnumerable <KeyValuePair <string, string> > extraHeaders = null, CancellationToken?cancellationToken = null) { CancellationToken cancelToken = cancellationToken ?? CancellationToken.None; Frame frame = StompFrameFactory.CreateSend(destination, body, Encoding.UTF8, receipt, transaction, extraHeaders); return(writer.WriteAsync(frame, cancelToken)); }
public static Task WriteConnectAsync( this IStompFrameWriter writer, string host = null, string login = null, string passcode = null, Heartbeat heartbeat = null, IEnumerable <KeyValuePair <string, string> > extraHeaders = null, CancellationToken?cancellationToken = null) { CancellationToken cancelToken = cancellationToken ?? CancellationToken.None; Frame frame = StompFrameFactory.CreateConnect(writer.ProtocolVersion, host, login, passcode, heartbeat, extraHeaders); return(writer.WriteAsync(frame, cancelToken)); }
public static Task WriteSendAsync( this IStompFrameWriter writer, string destination, byte[] body = null, string contentType = MediaTypeNames.Application.Octet, string receipt = null, string transaction = null, IEnumerable <KeyValuePair <string, string> > extraHeaders = null, CancellationToken?cancellationToken = null) { CancellationToken cancelToken = cancellationToken ?? CancellationToken.None; Frame frame = StompFrameFactory.CreateSend(destination, body, contentType, receipt, transaction, extraHeaders); return(writer.WriteAsync(frame, cancelToken)); }
/// <summary> /// Constructor. /// </summary> /// <param name="writer">Frame writer.</param> /// <param name="frameObservable">Frame observable to be used to receive the confirmations.</param> /// <param name="retryInterval">When sending messages that requires receipt confirmation, /// this interval specifies how much time to wait before sending the frame again if /// no receipt is received.</param> public StompFrameWriterWithConfirmation(IStompFrameWriter writer, IStompFrameObservable frameObservable, TimeSpan? retryInterval = null) { if (writer == null) throw new ArgumentNullException("writer"); if (frameObservable == null) throw new ArgumentNullException("frameObservable"); if (frameObservable.ProtocolVersion != writer.ProtocolVersion) throw new ArgumentException("Reader and writer MUST use the same protocol version."); _writer = _writer as StompSerialFrameWriter ?? new StompSerialFrameWriter(writer); frameObservable.SubscribeEx(OnNext, OnError, OnCompleted); _receiptWaiters = new ConcurrentDictionary<string, TaskCompletionSource<object>>(); _retryInterval = retryInterval ?? DefRetryInterval; }
/// <summary> /// Constructor. /// </summary> /// <param name="writer">Frame writer.</param> /// <param name="frameObservable">Frame observable to be used to receive the confirmations.</param> /// <param name="retryInterval">When sending messages that requires receipt confirmation, /// this interval specifies how much time to wait before sending the frame again if /// no receipt is received.</param> public StompFrameWriterWithConfirmation(IStompFrameWriter writer, IStompFrameObservable frameObservable, TimeSpan?retryInterval = null) { if (writer == null) { throw new ArgumentNullException("writer"); } if (frameObservable == null) { throw new ArgumentNullException("frameObservable"); } if (frameObservable.ProtocolVersion != writer.ProtocolVersion) { throw new ArgumentException("Reader and writer MUST use the same protocol version."); } _writer = _writer as StompSerialFrameWriter ?? new StompSerialFrameWriter(writer); frameObservable.SubscribeEx(OnNext, OnError, OnCompleted); _receiptWaiters = new ConcurrentDictionary <string, TaskCompletionSource <object> >(); _retryInterval = retryInterval ?? DefRetryInterval; }
public static Task WriteHearbeatAsync(this IStompFrameWriter writer, CancellationToken?cancellationToken = null) { CancellationToken cancelToken = cancellationToken ?? CancellationToken.None; return(writer.WriteAsync(Frame.HeartbeatFrame, cancelToken)); }
/// <summary> /// Constructor. /// </summary> /// <param name="writer">Frame writer to be wrapped.</param> public StompSerialFrameWriter(IStompFrameWriter writer) { _writer = writer; _serialTaskExecuter = new SerialTaskExecuter(); }
public static Task WriteAsync(this IStompFrameWriter writer, Frame frame) { return(writer.WriteAsync(frame, CancellationToken.None)); }