Skip to content

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

Closed
@Quemoy

Description

@Quemoy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions