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

How do I publish raw Json messages ? #398

Open
iniside opened this issue Jun 16, 2019 · 1 comment
Open

How do I publish raw Json messages ? #398

iniside opened this issue Jun 16, 2019 · 1 comment

Comments

@iniside
Copy link

iniside commented Jun 16, 2019

Is it possible to publish raw Json Messages ?
Some context.
I have client apps, which connect to gateway service over websocket connection. Since clients can be in variety of from and languages I decided that best course of action would be to send messages as Json and then on gateway publish them to Rabbit.

I would like to avoid for gateway to know type of messages if possible. I just want it to act as dumb router and connection load balancer not message translation from clients.

I tried to find in docs and here but I couldn't find any example of how (and if possible) to do it, or how the Json message should be formatted.

@rpawlaszek
Copy link

Is it possible to publish raw Json Messages ?

Yes. This is set by default.

Ok, there is one thing, this setting will include $id property in the serialized messages, so if you want to prevent that you need to update the di. To do that specify a new ISerializer e.g. like this:

new RawRabbitOptions()
{
    ClientConfiguration = ...,
    DependencyInjection = di => di.AddSingleton<ISerializer, RawRabbit.Serialization.JsonSerializer>(resolver => new RawRabbit.Serialization.JsonSerializer(new Newtonsoft.Json.JsonSerializer
    {
	TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
	Formatting = Formatting.None,
	CheckAdditionalContent = true,
	ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() },
	ObjectCreationHandling = ObjectCreationHandling.Auto,
	DefaultValueHandling = DefaultValueHandling.Ignore,
	TypeNameHandling = TypeNameHandling.Auto,
	ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
	MissingMemberHandling = MissingMemberHandling.Ignore,
	PreserveReferencesHandling = PreserveReferencesHandling.None,
	NullValueHandling = NullValueHandling.Ignore
    }))
}

The only change with respect to the original is PreserveReferencesHandling = PreserveReferencesHandling.None (see here for explanation).

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

No branches or pull requests

2 participants