381.5. 使用消息
Yammer 组件为使用消息提供了几个端点:
URI | 描述 |
---|---|
yammer:messages?[options] | 用户(其访问令牌被用来发出 API 调用)Yammer 网络中的所有公共消息。对应于 Yammer Web 界面中的"所有"对话。 |
yammer:my_feed?[options] | 用户源,基于在"Follow"和"Top"对话之间所做的选择。 |
yammer:algo?[options] | 与"Top"对话对应的用户的算法源,这是大多数用户将在 Yammer web 界面中看到的。 |
yammer:following?[options] | "Following"源,对话涉及用户以下的人员、组和主题。 |
yammer:sent?[options] | 用户发送的所有消息。 |
yammer:private?[options] | 用户接收的专用消息。 |
yammer:received?[options] | Camel 2.12.1 : 用户收到的所有信息 |
381.5.1. 消息格式
默认情况下,所有消息都会转换为 org.apache.camel.component.yammer.model
软件包提供的 POJO 模型。来自 yammer 的原始消息采用 JSON。对于所有使用和生成端点的消息,会返回 Messages
对象。以如下方式为路由:
from("yammer:messages?consumerKey=aConsumerKey&consumerSecret=aConsumerSecretKey&accessToken=aAccessToken") .to("mock:result");
让我们说 yammer 服务器返回:
{ "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 将在包含 2 个 Message
对象的 Messages
对象中放入一个 Messages 对象中。如下所示,有一个丰富的对象模型,可以轻松地获取您需要的任何信息:
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());
这意味着,将这个数据嵌套到 POJO 中不是空闲的,因此如果您需要您可以通过将 useJson=false
选项添加到 URI 来切回到使用纯 JSON 的 JSON。