All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.zbus.rpc.transport.mq.RpcMessageHandler Maven / Gradle / Ivy

There is a newer version: 1.0.0-b1
Show newest version
package io.zbus.rpc.transport.mq;

import java.io.IOException;

import io.zbus.mq.Message;
import io.zbus.mq.MessageHandler;
import io.zbus.mq.MqClient;
import io.zbus.rpc.RpcProcessor;

public class RpcMessageHandler implements MessageHandler {
	
	private final RpcProcessor rpcProcessor;
	
	public RpcMessageHandler(RpcProcessor rpcProcessor) {
		this.rpcProcessor = rpcProcessor;
	}
	
	@Override
	public void handle(Message msg, MqClient client) throws IOException { 
		final String topic = msg.getTopic();
		final String msgId  = msg.getId();
		final String sender = msg.getSender();
		 
		io.zbus.transport.http.Message httpMsg = rpcProcessor.process(msg);
		Message res = new Message(httpMsg);
		if(res != null){
			res.setId(msgId);
			res.setTopic(topic);  
			res.setReceiver(sender);  
			if(res.getStatus() == null){
				res.setStatus(200); //default to 200, if not set
			}
			//route back message
			client.route(res);
		}
	} 
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy