`ActyxClient::publish` is too verbose
jmg-duarte opened this issue · comments
José Duarte commented
client
.publish(PublishRequest {
data: vec![PublishEvent {
tags: tags!("message"),
payload: Payload::compact(&event).expect("failed to serialize event"),
}],
})
.await
.expect("failed to publish event");
This function suffers from the same issue as #553.
- We can provide a function for a single event, or multiple events.
- Publishing several events with the same tags is also not ergonomic — the user is required to write down the tags multiple times.
Some like the following would be more ergonomic:
client.publish_events(&tags, vec![event1, event2])
- The
payload
detail could also be hidden from the user, just forcing the type that goes into the function to beT: Serializable
to match thecompact
constraint. While the user may construct a payload from a slice, I'm not expecting that to be the "normal case", currently, we usePayload::from_slice
in just two places: https://sourcegraph.com/search?q=context%3Aglobal+repo%3Agithub.com%2FActyx%2FActyx+Payload%3A%3Afrom_slice&patternType=standard&sm=1&groupBy=repo
For example:
client
.publish_event(tags!("hello", "there"), &event)
And we could still keep publish
as a more low-level abstraction (still keeping the Payload::compact
away from the user):
client.publish(vec![PublishEvent::new(tags!("hey", "there"), &event)])
Roland Kuhn commented
How about publish_single
and publish
? And we can remove the PublishEvent
type from this API and just use (Tags, T)
.