fedora-infra/fedmsg

python example does not work

Opened this issue ยท 10 comments

http://www.fedmsg.com/en/latest/#publishing-messages-with-python

the example given on homepage does not work (0.18.3):

$ cat publish.py
#!/usr/bin/python

import fedmsg
fedmsg.publish(topic='testing', modname='test', msg={
    'test': "Hello World",
})
$ ./publish.py
/usr/share/python2.7/site-packages/fedmsg/core.py:159: UserWarning: fedmsg is not configured to send any zmq messages for name '__main__.wintersunset'
Traceback (most recent call last):
  File "./publish.py", line 5, in <module>
    'test': "Hello World",
  File "/usr/share/python2.7/site-packages/fedmsg/__init__.py", line 79, in _wrapper
  File "/usr/share/python2.7/site-packages/fedmsg/__init__.py", line 94, in publish
  File "/usr/share/python2.7/site-packages/fedmsg/core.py", line 320, in publish
AttributeError: 'FedMsgContext' object has no attribute 'publisher'
$ 

however i had older test.py laying around that does work:

$ cat test.py 
#!/usr/bin/python

import fedmsg

# until this is in place, add name="relay_inbound": http://paste.fedoraproject.org/155599/74653371/

fedmsg.publish(topic='testing', modname='test', active=True, name="relay_inbound", msg={
        'test': "Hello World",
})

Hmm. I have a suspicion that this is a configuration/services problem of some kind. I tried both snippets and neither one worked for me. I'm going to label this as a docs issue until I can investigate further, but it might be a regression of some kind, as well. Either way, the docs need some attention.

either way, AttributeError: 'FedMsgContext' object has no attribute 'publisher' is ugly message to show, meaning error handling is not even in place. this should be handled and proper error be thrown. perhaps with a hint what configuration is missing. or some better defaults invented.

I definitely agree.

Hello @jeremycline , @glensc
I am new to this and I was following the docs when I faced the same issue as @glensc . I think the problem lies in core.py and a try case needs to be added.
The current doc example doesn't work because active is by default 'False' in config.py and it has to be overridden as 'True' from either publish() or .config dict as we are trying to publish through a relay.
Please let me know what you think, I am just trying to learn fedmsg usage.

@reCursedd that sounds reasonable. Another option would be to add something in the endpoints config.

Any updates on this?

As far as I know it's still present. I don't think it's worth fixing at this point since we're probably going to stop using fedmsg.

@jeremycline Could you point to some fedora-messaging migration resources for the benefit of those who come across this issue in the future?

There are a few GSoC / Outreachy projects blocked by this issue. I think there is confusion about the transition from fedmsg to fedora-messaging (that, or I am confused too). It will probably help to clarify how to migrate over.

@jwflory sure. And if anyone comes across this issue in the future, I'm happy to answer whatever questions you have.

The user guide and API guide at https://fedora-messaging.readthedocs.io/en/stable/ is a good place to start, and there's a section on converting from fedmsg to fedora-messaging: https://fedora-messaging.readthedocs.io/en/stable/tutorial/index.html.

One thing that adds a bit of confusion at the moment is that Fedora's broker cluster is inside the VPN and not accessible over the Internet. What still is currently accessible is the ZeroMQ PUB socket which is what fedmsg uses. It's on my backlog to address this, I just have other fires to tend at the moment.