Elastic Beanstalk Worker Tier返回400s

时间:2016-11-16 22:40:32

标签: java spring-mvc elastic-beanstalk

我有一个带有以下端点的基本spring应用程序:

@RestController
public class WorkerController {

    @Autowired    
    private WorkerService service;

    @RequestMapping(value = "/", method = RequestMethod.POST)
    public void receive(@RequestBody Long id) {
        service.receive(id);
    }
}

在另一个应用程序中,JMS(特别是Amazon的JMS SQS实现)用于写入该worker的队列:

public class ProducerService {

    private Session session;
    private MessageProducer producer;

    public ProducerService() {
        initializeSessionAndProducer()
    }

    private void initializeSessionAndProducer() { ... }

    public void sendMessage(Long id) {
        Message message = this.session.createObjectMessage(t);
        producer.send(message);
    }
}

两个应用程序都打包为docker镜像。这里有一些日志输出显示sqsd满足400。

2016-11-16T21:37:17Z message: sent to http://localhost:80
2016-11-16T21:37:18Z http-err: 321ca22b-8137-4970-ad8a-54dbe83cc6a7 (1) 400 - 0.494

这里是所有Elastic Beanstalk配置:

//  Scaling
//    Environment type: Single instance
//    Custom Availability Zones: blank
//  Instances
//    Instance type: t2.small
//    Availability Zones: Any
//  Notifications
//    Notifications: Off
//  Software Configuration
//    Environment variables: env
//    Log publication: On
//  Updates and Deployments
//    Deployment policy: All at once
//    Rolling updates are disabled
//  Worker Configuration
//    Worker queue URL https://sqs.us-west-2.amazonaws.com/id/WORKER
//    HTTP path: /
//    MIME type: application/json
//    HTTP connections: 50
//    Visibility timeout: 1800
//  Health
//    Application health check URL: blank
//    Health reporting: Basic
//  Managed Updates
//    Managed updates are disabled

我尝试修改我的端点以接收对象,但会出现相同的错误代码。有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

问题是控制器配置为当sqsd发送放在队列中的内容时接受application / json,这是一个base64编码的序列化Long。以下是该端点适应队列内容的方法:

@RequestMapping(value = "/", method = RequestMethod.POST)
public void runMicroservice(HttpServletRequest request) throws Exception {
    if (microservice != null) {
        byte b[] = Base64.getDecoder().decode(IOUtils.toString(request.getInputStream(), "UTF-8"));
        ByteArrayInputStream bi = new ByteArrayInputStream(b);
        ObjectInputStream si = new ObjectInputStream(bi);
        microservice.receiveMessage((Long) si.readObject());
    }
    else System.exit(-1);
}