Consuming messages - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

The camel-yammer component provides several endpoints for consuming messages:

URI

Description

yammer:messages?[options]

All public messages in the user's (whose access token is being used to make the API call) Yammer network. Corresponds to "All" conversations in the Yammer web interface.

yammer:my_feed?[options]

The user's feed, based on the selection they have made between "Following" and "Top" conversations.

yammer:algo?[options]

The algorithmic feed for the user that corresponds to "Top" conversations, which is what the vast majority of users will see in the Yammer web interface.

yammer:following?[options]

The "Following" feed which is conversations involving people, groups and topics that the user is following.

yammer:sent?[options]

All messages sent by the user.

yammer:private?[options]

Private messages received by the user.

yammer:received?[options]

Camel 2.12.1: All messages received by the user

URI Options for consuming messages

Name

Default Value

Description

useJson

false

Set to true if you want to use raw JSON rather than converting to POJOs.

delay

5000

in milliseconds

consumerKey

null

Consumer Key. Can also be configured on the YammerComponent level instead.

consumerSecret

null

Consumer Secret. Can also be configured on the YammerComponent level instead.

accessToken

null

Access Token. Can also be configured on the YammerComponent level instead.

limit

-1

Return only the specified number of messages. Works for threaded=true and threaded=extended.

threaded

null

threaded=true will only return the first message in each thread. This parameter is intended for apps which display message threads collapsed. threaded=extended will return the thread starter messages in order of most recently active as well as the two most recent messages, as they are viewed in the default view on the Yammer web interface.

olderThan

-1

Returns messages older than the message ID specified as a numeric string. This is useful for paginating messages. For example, if you're currently viewing 20 messages and the oldest is number 2912, you could append "?olderThan=2912″ to your request to get the 20 messages prior to those you're seeing.

newerThan

-1

Returns messages newer than the message ID specified as a numeric string. This should be used when polling for new messages. If you're looking at messages, and the most recent message returned is 3516, you can make a request with the parameter "?newerThan=3516″ to ensure that you do not get duplicate copies of messages already on your page.

Message format

All messages by default are converted to a POJO model provided in the org.apache.camel.component.yammer.model package. The original message coming from yammer is in JSON. For all message consuming & producing endpoints, a Messages object is returned. Take for example a route like:

from("yammer:messages?consumerKey=aConsumerKey&consumerSecret=aConsumerSecretKey&
accessToken=aAccessToken").to("mock:result");

and lets say the yammer server returns:

{
    "messages":[
        {
            "replied_to_id":null,
            "network_id":7654,
            "url":"https://www.yammer.com/api/v1/messages/305298242",
            "thread_id":305298242,
            "id":305298242,
            "message_type":"update",
            "chat_client_sequence":null,
            "body":{
                "parsed":"Testing yammer API...",
                "plain":"Testing yammer API...",
                "rich":"Testing yammer API..."
            },
            "client_url":"https://www.yammer.com/",
            "content_excerpt":"Testing yammer API...",
            "created_at":"2013/06/25 18:14:45 +0000",
            "client_type":"Web",
            "privacy":"public",
            "sender_type":"user",
            "liked_by":{
                "count":1,
                "names":[
                    {
                        "permalink":"janstey",
                        "full_name":"Jonathan Anstey",
                        "user_id":1499642294
                    }
                     
                ]
                 
            },
            "sender_id":1499642294,
            "language":null,
            "system_message":false,
            "attachments":[
                 
            ],
            "direct_message":false,
            "web_url":"https://www.yammer.com/redhat.com/messages/305298242"
        },
        {
            "replied_to_id":null,
            "network_id":7654,
            "url":"https://www.yammer.com/api/v1/messages/294326302",
            "thread_id":294326302,
            "id":294326302,
            "message_type":"system",
            "chat_client_sequence":null,
            "body":{
                "parsed":"(Principal Software Engineer) has [[tag:14658]] the 
                redhat.com network. Take a moment to welcome Jonathan.",
                "plain":"(Principal Software Engineer) has #joined the redhat.com 
                network. Take a moment to welcome Jonathan.",
                "rich":"(Principal Software Engineer) has #joined the redhat.com 
                network. Take a moment to welcome Jonathan."
            },
            "client_url":"https://www.yammer.com/",
            "content_excerpt":"(Principal Software Engineer) has #joined the redhat.com network. Take a moment to welcome Jonathan.",
            "created_at":"2013/05/10 19:08:29 +0000",
            "client_type":"Web",
            "sender_type":"user",
            "privacy":"public",
            "liked_by":{
                "count":0,
                "names":[
                     
                ]
                 
            }
        }  
        ]
         
    }

Camel will marshal that into a Messages object containing 2 Message objects. As shown below there is a rich object model that makes it easy to get any information you need:

Exchange exchange = mock.getExchanges().get(0);
Messages messages = exchange.getIn().getBody(Messages.class);
 
assertEquals(2, messages.getMessages().size());
assertEquals("Testing yammer API...", messages.getMessages().get(0).getBody().
getPlain());
assertEquals("(Principal Software Engineer) has #joined the redhat.com network. 
Take a moment to welcome Jonathan.", messages.getMessages().get(1).getBody().getPlain());

That said, marshaling this data into POJOs is not free so if you need you can switch back to using pure JSON by adding the useJson=false option to your URI.