Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README.rst listening code bug due to message schema #42

Open
Quemoy opened this issue Mar 20, 2023 · 0 comments
Open

README.rst listening code bug due to message schema #42

Quemoy opened this issue Mar 20, 2023 · 0 comments

Comments

@Quemoy
Copy link

Quemoy commented Mar 20, 2023

Hello. In README.rst, a suggested sample code for listening to message is:

def callback(message, subscription_id):
    print('Subscription ID: {}: Message: {}'.format(subscription_id, message.data.__str__()))
    return True  # If desired return False to stop the message flow. This will unblock the process as well.

listener.listen(callback, maximum_messages=10)  # Omitting maximum_messages means you will continue to get messages as they appear. Can be a firehose. Use with caution.
# You may pass subscription ID as a parameter to the listen function

However, using this code produces the following error:

Input In [1], in callback(message, subscription_id)
      8 def callback(message, subscription_id):
      9     print('Subscription ID: {}: Message: {}'.format(subscription_id, 
---> 10                                                     message.data.__str__()))
     11     return True

AttributeError: 'dict' object has no attribute 'data'

This seems like because the schema for a message is different. This is what a message looks like from the streams:

{'an': 'DUBQTELH20230317ej3g00046', 'document_type': 'article', 'action': 'del', 's
ource_code': 'DUBQTELH', 'source_name': 'Telegraph Herald', 'publication_date': '2023-03-16T00:00:00
.000Z', 'publication_datetime': '2023-03-16T00:00:00.000Z', 'modification_date': '2023-03-20T04:33:5
9.600Z', 'modification_datetime': '2023-03-20T04:33:43.000Z', 'ingestion_datetime': '2023-03-20T04:3
3:43.000Z', 'attrib_code': 'DUBQTELH', 'authors': [], 'clusters': []}

e.g., there's no longer a data field in the message.

The code in the demo directory does not seem to have this problem. However, the documentation on the developer platform does say that a message has a 'data' field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant