使用C#的ShortCode吞吐量的Twilio Bulk消息

时间:2015-05-29 14:16:30

标签: c# twilio

我正在尝试追踪一个性能问题,该问题不允许我使用twilio c#api发送超过3条左右的消息。简而言之,我们有一个响应批量“JOIN”消息的Windows服务。请参阅以下代码:

        int i = 0;
        DateTime d = DateTime.Now;
        TimeSpan ts = new TimeSpan(0,0,1);
        foreach (CustomerTextMessage t in o)
        {
            i++;
            ThreadInput ti = new ThreadInput { MessageIds = i, Body = t.Body, ThreadCreated = DateTime.Now, FromNumber = t.FromNumber };
            ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessResponseList), (object)ti);
        }

ProcessResponseList方法快速查看客户,然后使用此方法进行响应:

    public static void SendResponse(string number, string body)
    {
        string AccountSid = ConfigurationManager.AppSettings["AccountSid"];
        string AuthToken = ConfigurationManager.AppSettings["AccountToken"];
        var twilio = new TwilioRestClient(AccountSid, AuthToken);


        string fromNumber = "";

        if (ConfigurationManager.AppSettings["StageExecution"] == "true")
        {
            BusinessLayer.SLOSBL.Logger logger = new BusinessLayer.SLOSBL.Logger("DiscoverTextMessagingService", "DiscoverTextMessagingService");
            AuthToken = ConfigurationManager.AppSettings["StageApplicationToken"];
            var longCodes = twilio.ListIncomingPhoneNumbers(null, "StagePhoneNumber", null, null);
            fromNumber = longCodes.IncomingPhoneNumbers[1].PhoneNumber;
            logger.Notify("Sending text message to:  " + number + " from Twilio number:  " + fromNumber + ".  The body of the message reads:  " + body);
        }
        else
        {
            var shortCodes = twilio.ListShortCodes(null, null);
            fromNumber = "+" + shortCodes.ShortCodes[0].ShortCode;
        }

        //var message = twilio.SendMessage(fromNumber, number, body, new string[0], null, AuthToken );
        DateTime d = DateTime.Now;

        twilio.SendMessage(fromNumber, number, body, new string[0], null, AuthToken, null, m => { MessageAsyncCallBack(m, d); });

    }

我所看到的是它能够每秒发送大约3条消息。我真的希望每隔一秒就增加一个更接近30的短代码,但我甚至无法让它们足够快地进入twilio队列。所以我的问题是,有什么明显的我应该做的吗?我是否应该为所有消息重用TwilioRestClient变量?我错过的某个地方的连接数是否有限制?提前谢谢。

0 个答案:

没有答案