douruyun8153 2014-08-07 07:37
浏览 50
已采纳

Thruway PubSub可以在发布之前修改消息吗?

chat application example.

Mr A (07-Aug-2017 15:01) : hello all
Mr B (07-Aug-2017 15:20) : hello Mr A

The Server Date Time (dd-mmm-yyyy hh:mm) is inserted by Server. Which I can easy done in Ratchet.
Ratchet.Wamp.WampServerInterface api document
Inside the OnPublish, Where I can amend the message before really publish out.

Can Thruway do the same ? I cannot find any Thruway doc, and I see the examples but not found what I want.Thruway Examples

  • 写回答

1条回答 默认 最新

  • douqian2957 2014-08-07 13:52
    关注

    I think if I needed to accomplish this, I would use a slightly different architecture. I believe the idea of WAMP is to keep the router very generic. That is why we don't have any examples of this.

    “All application specific code should reside in WAMP application components, not in the router itself.” —tobias

    That being said, it still would not be too difficult to do what you want to do - but would require intercepting the messages. Ideally, it would be nice to override the Broker - but we don't have a generic way to switch that out right now. So we can override the Router and inspect every message:

    class MyRouter extends Router {
        public function onMessage(TransportInterface $transport, Message $msg) {
            if ($msg instanceof PublishMessage) {
                if ($msg->getTopicName() == "mytopic") {
                    // mangle the message in here
                }
            }
    
            parent::onMessage($transport, $msg);
        }
    }
    

    Then just use this class instead of the default Router when you are starting up.

    I have not tried this code, if I get a chance I will. The idea should work though.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?