305.4. 将消息发送到 SIP 端点


305.4.1. 创建 Camel SIP publisher

在以下示例中,创建了一个 SIP publishers,将 SIP Event publications 发送到
用户 "agent@localhost:5152"。这是 SIP Presence Agent 的地址,它充当 SIP publisher 和 Subscriber 之间的代理

  • 使用名为 client 的 SIP Stack
  • 使用名为 evtHdrName 的基于 registry 的事件标头
  • 使用基于 registry 的 eventId,名为 evtId
  • 从将 Listener 设置为 user2@localhost:3534 的 SIP 堆栈
  • 发布的事件是 EVENT_A
  • 名为 REQUEST_METHOD 的 Mandatory Header 设置为 Request.Publish,因此将端点设置为 Event publisher"
producerTemplate.sendBodyAndHeader(
    "sip://agent@localhost:5152?stackName=client&eventHeaderName=evtHdrName&eventId=evtid&fromUser=user2&fromHost=localhost&fromPort=3534",
    "EVENT_A",
    "REQUEST_METHOD",
    Request.PUBLISH);
Copy to Clipboard Toggle word wrap

305.4.2. 创建 Camel SIP Subscriber

在以下示例中,创建了一个 SIP Subscriber 来接收发送到
的 SIP Event publications 用户 "johndoe@localhost:5154"

  • 使用名为 Subscriber 的 SIP Stack
  • 使用名为 agent@localhost:5152 的 Presence Agent 用户注册
  • 使用名为 evtHdrName 的基于 registry 的事件标头。evtHdrName 包含事件,其 se to "Event_A"
  • 使用基于 registry 的 eventId,名为 evtId
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // Create PresenceAgent
            from("sip://agent@localhost:5152?stackName=PresenceAgent&presenceAgent=true&eventHeaderName=evtHdrName&eventId=evtid")
                .to("mock:neverland");

            // Create Sip Consumer(Event Subscriber)
            from("sip://johndoe@localhost:5154?stackName=Subscriber&toUser=agent&toHost=localhost&toPort=5152&eventHeaderName=evtHdrName&eventId=evtid")
                .to("log:ReceivedEvent?level=DEBUG")
                .to("mock:notification");

        }
    };
}
Copy to Clipboard Toggle word wrap

Camel SIP 组件也附带一个 Presence Agent,它仅用于测试和演示目的。上面提供了一个实例化预备代理的示例。

请注意,Presence Agent 设置为一个用户 agent@localhost:5152,能够同时与 publisher 和 Subscriber 进行通信。它一个独立的 SIP stackName 与 publisher 和 Subscriber 不同。虽然它被设置为 Camel Consumer,但它实际上不会向端点 "mock:neverland" 发送任何信息。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat