karstenhopp (karstenhopp) wrote,
karstenhopp
karstenhopp

Changing code to use fedora-messaging instead of fedmsg

A good start to find out about the required code changes to get rid of fedmsg in favour of fedora-messaging is to check the changes that are already done in other components. For example waiverdb


Apart from some changes to the tests, the required code change boils down to creating a msg with a new format and then pushing it to the message bus with 'publish' from fedora_messaging.api instead of 'fedmsg.publish'


-                 fedmsg.publish(topic='waiver.new', msg=marshal(row, waiver_fields))
+                 msg = Message(
+                     topic='waiverdb.waiver.new',
+                     body=marshal(row, waiver_fields)
+                 )
+                 publish(msg)

OFC exceptions need to be modified slightly, too, but altogether this seems pretty straightforward.


-             except Exception:
-                 _log.exception('Couldn\'t publish message via fedmsg')
+             except PublishReturned as e:
+                 _log.exception('Fedora Messaging broker rejected message %s: %s', msg.id, e)
+                 monitor.messaging_tx_failed_counter.inc()
+             except ConnectionException as e:
+                 _log.exception('Error sending message %s: %s', msg.id, e)
Tags: fedora, linux
Subscribe

Recent Posts from This Journal

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments