2

我正在尝试在 ColdFusion 中运行 3 个 http 请求线程。这是一个电子邮件系统,它将选择 3 个不同的活动并同时向相应的收件人发送。

但是我下面的代码只运行一个线程然后就掉线了。

   <cfscript>
        newsLetterCampaignGateway = createObject("component", "legacy.ssl.admin.news.model.newsLetterCampaignGateway");
        newsLetterList = newsLetterCampaignGateway.getNewsLettersDueForSend();
        //writedump(newsLetterList);abort;

    </cfscript> 

  <cfloop query="newsLetterList" >
    <cfset newsLetterId =  newsLetterList.newsletterid>
    <cfset campId =  newsLetterList.id>
    <cfset fromEmail =  newsLetterList.fromEmail>

    <!--- <cfdump var="#campId#"> --->
    <cfthread action="run" name="runCampaign#campId#" >
        <cflock
            name="runCampaign_#campId#_Lock"
            type="exclusive"
            timeout="60">
            <!--- <cfdump var="#campId#"> --->
            <cfscript>      
                httpService = new http(); 
                httpService.setMethod("get"); 
                httpService.setCharset("utf-8"); 
                httpService.setUrl("http://mysamplesite.com/legacy/ssl/admin/news/model/newsLettercampaign.cfc"); 
                httpService.addParam(type="url",name="method",value="sendCampaignNewsLetters"); 
                httpService.addParam(type="url",name="live",value="true"); 
                httpService.addParam(type="url",name="campaignId",value="#campId#"); 
                httpService.addParam(type="url",name="newsLetterId",value="#newsLetterId#"); 
                httpService.addParam(type="url",name="fromEmail",value="#fromemail#"); 
                httpService.send();
            </cfscript> 
        </cflock>
    </cfthread>

  </cfloop>


    <cfloop query="newsLetterList" >

            <cfthread
            action="join"
            name="runCampaign#campId#"
            />
    </cfloop>

有什么想法吗?

4

1 回答 1

0

好吧,我决定不使用 cfhttp 并使用这样的线程并且它可以工作。

<cfsetting requesttimeout="300000">
<cfscript>
    newsLetterCampaignGateway = createObject("component", "path.to.cfc");
    newsLetterList = newsLetterCampaignGateway.getNewsLettersDueForSend();
</cfscript>


  <cfloop query="newsLetterList" >

    <cftry>
        <cfthread action="run" name="runCampaign#url.campaignId#" >
            <cfset sendRequest(url)>
        </cfthread>

    <cfcatch>
        <cfdump var="#cfcatch#"><cfabort>
    </cfcatch>
    </cftry>

  </cfloop>

<cffunction name="sendRequest">
    <cfargument name="urlStu" required="true">

    <cfset newsLettercampaign = createObject("component", "path.to.cfc")>
    <cfset newsLettercampaign.sendCampaignNewsLetters(arguments.urlStu)>

</cffunction>
于 2013-08-01T16:21:06.717 回答