Asterisk-Java AGI。启动方法运行时,DefaultAgiServer freez

时间:2018-05-21 11:38:29

标签: java spring agi asterisk-java

尝试使用agi来听星号。

但是在启动方法运行后,我的应用程序正在冻结。没有出现错误...

我的春豆:

@Bean(name = "agi")
public DefaultAgiServer getAsteriskAgi() throws Exception {
    DefaultAgiServer agiServer = new DefaultAgiServer();
    agiServer.startup();
    return agiServer;
}

我的映射

public class AsteriskAgi extends BaseAgiScript{
@Override
public void service(AgiRequest agiRequest, AgiChannel agiChannel) throws AgiException {
    // Answer the channel...
    answer();
    // ...say hello...
    streamFile("welcome");
    streamFile("tt-monkeys");
    // ...and hangup.
    hangup();

}

}

我的属性文件

fastagi-mapping.properties 

位于资源文件夹

为什么会这样?

UPD 最后两个控制台输出:

2018-05-21 15:19:53 DEBUG DefaultAgiServer:81 - Using channelFactory org.asteriskjava.fastagi.internal.DefaultAgiChannelFactory
2018-05-21 15:19:53  INFO DefaultAgiServer:315 - Listening on *:4573.

1 个答案:

答案 0 :(得分:1)

Tomcat在启动时挂起,因为AGI服务器正在阻止它并等待来自套接字连接link的传入AGI数据。 要解决这个问题,您应该将AgiServer包装在一个单独的线程中,以便它在后台运行或使用AgiServerThread

结果我的星号agi配置如下所示:

@Bean
public AgiServerThread agiServerThread(){
    AgiServerThread agiServerThread = new AgiServerThread(getDefaultAgiServer());
    agiServerThread.startup();
    return agiServerThread;
}

@Bean
public DefaultAgiServer getDefaultAgiServer(){
    return new DefaultAgiServer(getAsteriskAgiScript());
}

@Bean
public AgiScript getAsteriskAgiScript(){
    return new AsteriskAgi();
}