Hi Team,
Please let me know if anyone faced this issue. If yes then please let me know workaround if google pubsub not support null default value.
When I am trying to publish pusub message on topic through microservice getting Invalid schema error.
{ "name": "field1", "type": ["string", "null"] }
{ "name": "field1", "type": "string", "default": null }
{ "name": "field11", "type": [ "null","string"], "default": null }
Below one is exception I am getting :-
com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Invalid data in message: Message failed schema validation.
Thanks in advance.
Sandy
Solved! Go to Solution.
If you want to make the "method" field nullable in your Avro schema, you need to use a union type that includes both "null" and your enum type. Here's how you can modify your example to allow the "method" field to be either one of your enum values or null:
{
"name": "method",
"type": ["null", {
"type": "enum",
"name": "MethodEnum",
"symbols": [
"GET",
"POST",
"PUT",
"DELETE"
]
}]
}
In this example, the "method" field can be either "GET", "POST", "PUT", "DELETE", or null. When you're creating your Avro data, if you want to set the "method" field to null, you can simply assign it the value null:
{
"method": null
}
And if you want to set it to one of your enum values, you can assign it that value:
{
"method": "GET"
}
Please Note: you'll need to serialize this data into a string before you publish it to Pub/Sub, and then deserialize it when you receive the message. The application that's consuming the messages also needs to be aware of this schema in order to properly interpret the data.