想要发布到远程计算机上的消息队列

时间:2019-05-16 20:27:57

标签: rabbitmq spring-amqp spring-rabbitmq spring-rabbit

我想从本地运行的springboot应用程序将消息pojo发布到驻留在其中一台远程机器上的消息队列,但是它给Authentication失败提供了例外。我可以将同一对象发布到本地的消息队列中。

我正在使用Springbatch读取,处理和写入消息队列。我已经使用过AmqpItemWriter并尝试发布到消息队列。它运作良好,并将消息发布到本地的消息队列中。当我将spring.rabbitmq.host属性从“ localhost”更改为“ xxx.xx.xx.xxx”时,远程计算机出现运行时异常,表明身份验证失败。

下面是我的Writer代码,在这里我有逻辑可以发布到消息队列。

@Component
public class Writer extends AmqpItemWriter<CsvWrapperPojo> {

    @Autowired
     @Qualifier("rabbitTemplate")
     private RabbitTemplate rabbitTemplate;

    public Writer(AmqpTemplate rabbitTemplate) {
        super(rabbitTemplate);
        // TODO Auto-generated constructor stub
    }

    /*@Autowired
    private CSVPostProcess csvPostProcess;*/


    @Override
    public void write(final List<? extends CsvWrapperPojo> items) throws Exception {
        // TODO Auto-generated method stub

        for(CsvWrapperPojo item : items){



            for(CSVPojo pojo :item.getGeneralPojoList()){

            rabbitTemplate.convertAndSend("spring-boot-rabbitmq-BulkSolve.async_BulkSolve_Msg", "BulkSolve_GeneralrequestQueue", pojo);
            }
            for(CSVPojo pojoSummary : item.getSummaryPojoList()){
                rabbitTemplate.convertAndSend("spring-boot-rabbitmq-BulkSolve_summary.async_BulkSolve_Msg", "BulkSolve_SummaryrequestQueue", pojoSummary);
            }
        }

    }



}

下面是application.properties

server.port=9060
spring.rabbitmq.dynamic=true
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.host=xxx.xx.xx.xxx(Remote machine IP)
spring.batch.job.enabled=false

我已经安装了Rabbitmq,并且远程计算机上也有相同的队列。但是似乎认证没有在这里进行。以下是我的异常堆栈跟踪。谁能建议将消息​​发布到远程计算机需要做什么。

java.net.SocketException: Socket Closed
        at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_131]
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_131]
        at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_131]
        at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_131]
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_131]
        at java.io.BufferedInputStream.read(BufferedInputStream.java:265) ~[na:1.8.0_131]
        at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) ~[na:1.8.0_131]
        at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[amqp-client-4.0.3.jar!/:4.0.3]
        at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) ~[amqp-client-4.0.3.jar!/:4.0.3]
        at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:571) ~[amqp-client-4.0.3.jar!/:4.0.3]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]

2019-05-16 15:56:41.683 ERROR 696 --- [nio-9060-exec-1] o.s.batch.core.step.AbstractStep         : Encountered an error executing step ETL-CSV in job ETL

org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
        at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:65) ~[spring-rabbit-1.7.4.RELEASE.jar!/:na]
        at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:368) ~[spring-rabbit-1.7.4.RELEASE.jar!/:na]
        at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:573) ~[spring-rabbit-1.7.4.RELEASE.jar!/:na]
        at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1430) ~[spring-rabbit-1.7.4.RELEASE.jar!/:na]
        at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1411) ~[spring-rabbit-1.7.4.RELEASE.jar!/:na]
        at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:712) ~[spring-rabbit-1.7.4.RELEASE.jar!/:na]
        at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:780) ~[spring-rabbit-1.7.4.RELEASE.jar!/:na]
        at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:776) ~[spring-rabbit-1.7.4.RELEASE.jar!/:na]
        at com.comcast.FileProcess.Batch.Writer.write(Writer.java:47) ~[classes!/:0.0.1-SNAPSHOT]
        at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175) ~[spring-batch-core-3.0.8.RELEASE.jar!/:3.0.8.RELEASE]
        at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151) ~[spring-batch-core-3.0.8.RELEASE.jar!/:3.0.8.RELEASE]
        at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:274) ~[spring-batch-core-3.0.8.RELEASE.jar!/:3.0.8.RELEASE]
        at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:199) ~[spring-batch-core-3.0.8.RELEASE.jar!/:3.0.8.RELEASE]
        at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75) ~[spring-batch-core-3.0.8.RELEASE.jar!/:3.0.8.RELEASE]
        at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) ~[spring-batch-core-3.0.8.RELEASE.jar!/:3.0.8.RELEASE]
        at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330) ~[spring-batch-core-3.0.8.RELEASE.jar!/:3.0.8.RELEASE]

1 个答案:

答案 0 :(得分:2)

guest/guest默认情况下不允许远程访问。

请参见"guest" user can only connect from localhost

  

默认情况下,禁止来宾用户从远程主机进行连接;它只能通过回送接口(即本地主机)进行连接。无论协议如何,这都适用于连接。 (默认情况下)其他任何用户都不会受到这种方式的限制。

继续说明如果您确实想允许它重新配置代理。