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

Allow to send raw jtoken/jobject instead object #321

Open
mcdis opened this issue Apr 26, 2019 · 4 comments
Open

Allow to send raw jtoken/jobject instead object #321

mcdis opened this issue Apr 26, 2019 · 4 comments

Comments

@mcdis
Copy link

mcdis commented Apr 26, 2019

Allow to send raw jtoken/jobject instead object in IRestChannel.PublishAsync

┆Issue is synchronized with this Jira Task by Unito

@mattheworiordan
Copy link
Member

Hi @mcdis. Can you elaborate on your use case please?

@mattheworiordan mattheworiordan added the enhancement New feature or improved functionality. label May 2, 2019
@mcdis
Copy link
Author

mcdis commented May 7, 2019

Hi @mattheworiordan!
We have got micro services arch and one type of service is targeting to collecting data in json and sending them to configured channel to configured queue system. One of available target queue system is Ably.
So message aggregation works with not typed json messages and at this moment we are converting them to string because raw jobject publishing doesn't work well.

@mattheworiordan
Copy link
Member

Thanks for the response, will get @withakay to look at soon.

@marto83
Copy link
Contributor

marto83 commented Oct 22, 2019

Hi @mcdis. There might be a small issue depending on which version of the library you are using. We currently bundle json.net with the ably binary in .net and xamarin to stop people having issues if they are using older version of the json.net. I don't know if exposing a jtoken class will be the same as you are using.

Currently there is a way to pass json directly. You can package it an encoded Message object as described in this ticket: #92 (comment)

You can pass a json object to ably at the moment and you will get a JObject back on the other side. I'm sure this will work fine if the services are .net core but need to test it in .Net Framework.

If you want to send a json string and you don't want ably to try and decode it on the way back then you can create a message with a custom encoding and the library won't touch the json string so you can choose whether to parse it or not. Here is a test showing how that works:

    public async Task SendAndReceiveJson(Protocol protocol)
    {
        var client = await GetRealtimeClient(protocol);

        await client.WaitForState(ConnectionState.Connected);

        var jobject = JObject.Parse("{ \"test\":\"test\"}");

        void PublishJson(IRealtimeChannel c, string name, JToken jsonToken)
        {
            var ablyMessage = new Message(name, jsonToken.ToString()) { Encoding = "custom" };

            c.Publish(ablyMessage);
        }

        var channel = client.Channels.Get("test");
        var awaiter = new TaskCompletionAwaiter();
        channel.Subscribe(message =>
        {
            message.Encoding.Should().Be("custom");
            message.Data.Should().BeOfType<string>();
            awaiter.Tick();
        });

        PublishJson(channel, "json", jobject);

        await awaiter.Task;
    }

@sync-by-unito sync-by-unito bot removed the enhancement New feature or improved functionality. label Feb 6, 2023
@sacOO7 sacOO7 mentioned this issue Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants