2016-11-16 67 views
0

我有以下端点的基本弹簧应用:弹性豆茎工人层返回400S

@RestController 
public class WorkerController { 

    @Autowired  
    private WorkerService service; 

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

在另一应用中,JMS(具体Amazon的SQS实现JMS的)被用来写入该工人的队列:

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); 
    } 
} 

这两个应用程序都打包为泊坞窗图像。下面是一些日志输出,显示了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 

这里的所有弹性魔豆配置:

// 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 

我试图修改我的终端来接收的对象,但相同的出现错误代码。有没有人有任何想法我可以解决这个问题?

回答

0

问题是控制器被配置为在sqsd发送放在队列上的一个base64编码的序列化的Long时接受application/json。以下是端点容纳队列内容的一种方式:

@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); 
}