public void ack_messages_can_ack_all_since_we_dont_allow_multiple_pending_messages_with_client_individual_ack_type() { var channel = Substitute.For <ITcpChannel>(); var transactionManager = Substitute.For <ITransactionManager>(); var client = Substitute.For <IStompClient>(); var subscription = new Subscription(client, "abc"); subscription.AckType = "client"; var frame1 = new BasicFrame("MESSAGE"); frame1.AddHeader("message-id", "kdkd1"); var frame2 = new BasicFrame("MESSAGE"); frame2.AddHeader("message-id", "kdkd2"); var frame3 = new BasicFrame("MESSAGE"); frame3.AddHeader("message-id", "kdkd3"); subscription.Send(frame1); subscription.Send(frame2); subscription.Send(frame3); var sut = new StompClient(channel, transactionManager); sut.AddSubscription(subscription); sut.AckMessages("kdkd2"); var actual1 = sut.IsFramePending("kdkd1"); var actual2 = sut.IsFramePending("kdkd2"); var actual3 = sut.IsFramePending("kdkd3"); actual1.Should().BeFalse(); actual2.Should().BeFalse(); actual3.Should().BeTrue(); }
public void send_message() { var frame = new BasicFrame("SEND"); frame.AddHeader("destination", "/queue/a"); frame.AddHeader("receipt", "message-12345"); frame.Body = new MemoryStream(Encoding.ASCII.GetBytes("hello queue a")); var expected = "SEND\ndestination:/queue/a\nreceipt:message-12345\ncontent-length:13\n\nhello queue a\0"; var buffer = new SocketBufferFake(); var encoder = new StompEncoder(); encoder.Prepare(frame); encoder.Send(buffer); var actual = Encoding.ASCII.GetString(buffer.Buffer, 0, buffer.Count); actual.Should().Be(expected); }
private static BasicFrame CreateOutboundMessage(IStompClient client, IFrame request) { var message = new BasicFrame("MESSAGE"); foreach (var header in request.Headers) { message.AddHeader(header.Key, header.Value); } message.AddHeader("Originator-Session", client.SessionKey); message.AddHeader("Originator-Address", client.RemoteEndpoint.ToString()); if (request.Body != null) { message.Body = new MemoryStream(); request.Body.CopyTo(message.Body); message.Body.Position = 0; } return(message); }
public void get_existent_subscription() { var client = Substitute.For <IStompClient>(); var subscription = new Subscription(client, "abc"); var frame = new BasicFrame("MESSAGE"); frame.AddHeader("message-id", "kdkd"); subscription.AckType = "client-individual"; subscription.Send(frame); var actual = subscription.IsMessagePending("kdkd"); actual.Should().BeTrue(); }
public void sent_message_should_be_pending_using_client_ack_type() { var channel = Substitute.For <ITcpChannel>(); var transactionManager = Substitute.For <ITransactionManager>(); var client = Substitute.For <IStompClient>(); var subscription = new Subscription(client, "abc"); var frame = new BasicFrame("MESSAGE"); frame.AddHeader("message-id", "kdkd"); subscription.AckType = "client"; subscription.Send(frame); var sut = new StompClient(channel, transactionManager); sut.AddSubscription(subscription); var actual = sut.IsFramePending("kdkd"); actual.Should().BeTrue(); }
public void get_existent_subscription() { var channel = Substitute.For <ITcpChannel>(); var transactionManager = Substitute.For <ITransactionManager>(); var client = Substitute.For <IStompClient>(); var subscription = new Subscription(client, "abc"); var frame = new BasicFrame("SEND"); frame.AddHeader("message-id", "kdkd"); subscription.AckType = "client-individual"; subscription.Send(frame); var sut = new StompClient(channel, transactionManager); sut.AddSubscription(subscription); var actual = sut.GetSubscription("kdkd"); actual.Should().BeSameAs(subscription); }
public IFrame Process(IStompClient client, IFrame request) { var id = request.Headers["receipt"]; if (string.IsNullOrEmpty(id)) { throw new BadRequestException(request, "Missing the 'receipt' header in the frame. It's required so that we can notify you when the DISCONNECT frame has been received."); } if (client.HasActiveTransactions) { throw new BadRequestException(request, "Got pending transactions. Just close the socket to abort them, or send proper commits/rollbacks before the DISCONNECT frame.."); } var response = new BasicFrame("RECEIPT"); response.AddHeader("receipt-id", id); return(response); }
public void just_ack_messages_up_to_the_given_one() { var client = Substitute.For <IStompClient>(); var frame1 = new BasicFrame("MESSAGE"); var frame2 = new BasicFrame("MESSAGE"); var frame3 = new BasicFrame("MESSAGE"); frame1.AddHeader("message-id", "kdkd1"); frame2.AddHeader("message-id", "kdkd2"); frame3.AddHeader("message-id", "kdkd3"); var sut = new Subscription(client, "abc"); sut.AckType = "client"; sut.Send(frame1); sut.Send(frame2); sut.Send(frame3); sut.Ack("kdkd2"); sut.IsMessagePending("kdkd1").Should().BeFalse(); sut.IsMessagePending("kdkd2").Should().BeFalse(); sut.IsMessagePending("kdkd3").Should().BeTrue(); }
private void OnHeaderName(string name, string value) { _frame.AddHeader(name, value); }