Hi Kara,
Good question!
You are right - it does not seem the most elegant way to do things -
the topic is duplicated and violates the DRY principle amongst other
things.
However, it is there for a good reason - when a JSON payload is
created it gets transformed internally ready to be sent over the wire
- so that when the server comes to publishing the payload it can
immediately send it without having to waste precious CPU cycles
extracting the topic from the payload or transforming the payload in
to its on-the-wire form. It is a very minor optimization but it has
been profiled against the alternative you suggested and came out on
top. When you are sending tens of thousands of messages a second this
seemingly over-the-top optimization increases the throughput.
A little undocumented trick for you, the topic in a JSON payload is
internally stored as a field with the key "topic" so you can't do
payload.getTopic() but you can do payload.getFields().get("topic"). ;)