380.5. 消耗消息
Yammer 组件为消耗消息提供了多个端点:
URI | 描述 |
---|---|
yammer:messages?[options] | 用户的所有公共消息(其访问令牌用于进行 API 调用)Yammer 网络。对应于 Yammer Web 界面中的"所有"对话。 |
yammer:my_feed?[options] | 用户反馈,根据他们在"Following"和"回复"对话之间作出的选择。 |
yammer:algo?[options] | 与"Top"对话对应的用户的算法源,这是大多数用户在 Yammer Web 界面中看到的内容。 |
yammer:following?[options] | "后续"反馈,是涉及用户所遵循的人员、组和主题的对话。 |
yammer:sent?[options] | 用户发送的所有消息。 |
yammer:private?[options] | 用户接收的专用消息。 |
yammer:received?[options] | Camel 2.12.1: 用户接收的所有消息 |
380.5.1. 消息格式
默认情况下,所有消息都会转换为 org.apache.camel.component.yammer.model
包中提供的 POJO 模型。来自 yammer 的原始消息采用 JSON。对于消耗和生成端点的所有消息,将返回 Messages
对象。使用类似以下的路由示例:
from("yammer:messages?consumerKey=aConsumerKey&consumerSecret=aConsumerSecretKey&accessToken=aAccessToken") .to("mock:result");
和 lets 表示 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 消息
对象的 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());
具体说,通过向您的 URI 添加 使用Json=false
选项,则将此数据进行汇总为 POJO 不可行。