Reuse the transaction before getting messages

The message get helper for claims used its own connection and ran
outside the transaction where the 'claiming' happened. This caused the
get to fail at retrieving the messages because the query was being
executed 'before' the transaction.

This patch fixes the aforementioned issue and also ensures that records
ids are 'int' before calling `message_encode`.

Change-Id: I076ffc171adf02fdb15160b6c7b29646ee3fb280
Closes-bug: #1288820