Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to pull message from jetstream #364

Closed
johnsusi opened this issue Feb 10, 2020 · 0 comments · Fixed by #365
Closed

Error when trying to pull message from jetstream #364

johnsusi opened this issue Feb 10, 2020 · 0 comments · Fixed by #365

Comments

@johnsusi
Copy link

Trying out the new Jetstream server causes an issue with RequestAsync.

An exception is thrown when parsing the response

https://github.com/nats-io/nats.net/blob/3558232a673d65d4440050bb96492f2645f43892/src/NATS.Client/Conn.cs#L2597-L2605

Here, e.Message.Subject = "foo.inc" and globalRequestInbox = "_INBOX.OpwL1p-dK8wVoYOZ20GWIy"

Exception has occurred: CLR/System.ArgumentOutOfRangeException
Exception thrown: 'System.ArgumentOutOfRangeException' in System.Private.CoreLib.dll: 'startIndex cannot be larger than length of string.'
   at System.String.Substring(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex)
   at NATS.Client.Connection.requestResponseHandler(Object sender, MsgHandlerEventArgs e)

Adding a minimal example for the issue.

Running on osx and using latest nats-server and jsm utility from source but had the same issue running the synadia/jsm:0.0.6 images in docker and NATS.Client 0.10.0

// # Start server
// ./nats-server -js

// test-jetstream % ./jsm str create
// ? Stream Name foo
// ? Subjects to consume foo.*
// ? Storage backend memory
// ? Retention Policy Limits
// ? Message count limit -1
// ? Message size limit -1
// ? Maximum message age limit -1
// ? Maximum individual message size -1
// Stream foo was created

// Information for Stream foo

// Configuration:

//              Subjects: foo.*
//      Acknowledgements: true
//             Retention: Memory - Limits
//              Replicas: 1
//      Maximum Messages: -1
//         Maximum Bytes: -1
//           Maximum Age: 0s
//  Maximum Message Size: -1
//     Maximum Consumers: -1

// State:

//             Messages: 0
//                Bytes: 0 B
//             FirstSeq: 0
//              LastSeq: 0
//     Active Consumers: 0



// test-jetstream % ./jsm con create
// ? Select a Stream foo
// ? Consumer name bar
// ? Delivery target
// ? Start policy (all, last, 1h, msg sequence) all
// ? Filter Stream by subject (blank for all)
// ? Maximum Allowed Deliveries -1
// Information for Consumer foo > bar

// Configuration:

//         Durable Name: bar
//            Pull Mode: true
//          Deliver All: true
//           Ack Policy: explicit
//             Ack Wait: 30s
//        Replay Policy: instant

// State:

//   Last Delivered Message: Consumer sequence: 0 Stream sequence: 0
//     Acknowledgment floor: Consumer sequence: 0 Stream sequence: 0
//         Pending Messages: 0
//     Redelivered Messages: 0


using System;
using System.Text;
using System.Threading.Tasks;
using NATS.Client;

namespace src
{
  public class Program
  {

    public static async Task Main(string[] args)
    {
      try
      {
        var options = ConnectionFactory.GetDefaultOptions();
        options.Url = "nats://localhost:4222";
        // Works when set to true
        // options.UseOldRequestStyle = true;

        using var connection = new ConnectionFactory().CreateConnection(options);

        // Publish some data to stream
        connection.Publish("foo.inc", Encoding.UTF8.GetBytes("Hello, World"));
        connection.Flush();

        // Try to read back one message
        var msg = await connection.RequestAsync("$JS.STREAM.foo.CONSUMER.bar.NEXT", Encoding.ASCII.GetBytes("1"));
        Console.WriteLine(Encoding.UTF8.GetString(msg.Data));
      }
      catch (Exception err)
      {
        Console.WriteLine(err.Message);
      }
    }
  }
}
<Project Sdk="Microsoft.NET.Sdk.Worker">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\nats.net\src\NATS.Client\NATS.Client.csproj" />
  </ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant