381.5. 使用消息
Yammer 组件为消耗消息提供多个端点:
URI | 描述 |
---|---|
yammer:messages?[options] | 用户的所有公共消息(其访问令牌用于发出 API 调用)Yammer 网络。对应于 Yammer Web 界面中的"所有"对话。 |
yammer:my_feed?[options] | 用户的源,基于他们在"Following"和"Top"对话之间所做的选择。 |
yammer:algo?[options] | 对应于"Top"对话的用户的算法源,这是 Yammer web 界面中大多数用户会看到的内容。 |
yammer:following?[options] | 涉及用户的人员、组和主题的"遵循"源。 |
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 将把 marshal 放入包含 2 个 Message
对象的 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 不能自由,因此如果您需要,您可以通过向 URI 中添加 useJson=false
选项,将纯 JSON 切换回使用纯 JSON。