The fedbadges fedmsg consumer is the main piece of Fedora Badges that grants badges to the service users. It consumes every message from the fedmsg bus, checks to see if that message matches a badge rule, and if it does, uses the Tahrir API (database API) to issue the badge to the user in the database.
Many badge rules require the consumer to know about past messages too, not just the one that triggered the rule. For example, a badge for 100 Bodhi comments requires a historical count of bodhi comment messages from the Datanommer (every message sent, ever) database. Note, however that currently the consumer interfaces directly with the Datanommer database, rather than using Datagrepper (been assumed so for performance reasons).
The badges rules are defined in YAML files are defined in a custom specification that is documented in the fedbadges documentation. For Fedora Badges, the badges rules are stored in the Fedora Badges repo and when new rules are added, copied over to the badges-backend01 server using the pushes-badges manual playbook.
Source repository: https://github.com/fedora-infra/fedbadges
Production location: badges-backend01.iad2.fedoraproject.org
Note: The messages consumer has some code in the main development branch that appears to start implementing support for Badgr. but this appears to be half-finished and was never deployed to production. It also appears to only send badges to badgr, and not store them in the tahrir database. So content can start here.
The messages consumer is written in Python 2.