[agent] start rabbitmq , continue a lot
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package io.wdd.rpc.init;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||
import io.wdd.common.handler.MyRuntimeException;
|
||||
import io.wdd.common.utils.MessageUtils;
|
||||
import io.wdd.server.beans.po.ServerInfoPO;
|
||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||
import io.wdd.server.utils.DaemonDatabaseOperator;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* The type Accept boot up info message.
|
||||
*/
|
||||
@Service
|
||||
public class AcceptBootUpInfoMessage {
|
||||
|
||||
|
||||
@Resource
|
||||
DaemonDatabaseOperator databaseOperator;
|
||||
|
||||
/**
|
||||
* Handle octopus agent boot up info.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
@RabbitHandler
|
||||
@RabbitListener(
|
||||
bindings =
|
||||
@QueueBinding(
|
||||
value = @Queue(name = "${octopus.message.init_to_server}"),
|
||||
exchange = @Exchange(name = "${octopus.message.init_exchange}", type = "direct"),
|
||||
key = {"${octopus.message.init_to_server_key}"}
|
||||
)
|
||||
,
|
||||
ackMode = "MANUAL"
|
||||
)
|
||||
public void handleOctopusAgentBootUpInfo(Message message) {
|
||||
|
||||
JsonMapper jsonMapper = new JsonMapper();
|
||||
ServerInfoVO serverInfoVO;
|
||||
|
||||
try {
|
||||
serverInfoVO = jsonMapper.readValue(message.getBody(), ServerInfoVO.class);
|
||||
} catch (IOException e) {
|
||||
throw new MyRuntimeException("parse rabbit server info error, please check !");
|
||||
}
|
||||
|
||||
|
||||
// 1. check if information is correct
|
||||
if(!validateServerInfo(serverInfoVO)){
|
||||
throw new MyRuntimeException("server info validated failed !");
|
||||
};
|
||||
// 2. generate the unique topic for agent
|
||||
String agentQueueTopic = generateAgentQueueTopic(serverInfoVO);
|
||||
// 3. save the agent info into database
|
||||
// backend fixed thread daemon to operate the database ensuring the operation is correct !
|
||||
if(!databaseOperator.saveInitOctopusAgentInfo(serverInfoVO)){
|
||||
throw new MyRuntimeException("database save agent info error !");
|
||||
}
|
||||
|
||||
// 4. send InitMessage to agent
|
||||
|
||||
}
|
||||
|
||||
private String generateAgentQueueTopic(ServerInfoVO serverInfoVO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean validateServerInfo(ServerInfoVO serverInfoVO) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package io.wdd.rpc.init;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class FromServerMessageBinding {
|
||||
|
||||
@Value("${octopus.message.init_exchange}")
|
||||
public String INIT_EXCHANGE;
|
||||
|
||||
@Value("${octopus.message.init_from_server}")
|
||||
public String INIT_FROM_SERVER;
|
||||
|
||||
@Value("${octopus.message.init_to_server}")
|
||||
public String INIT_TO_SERVER;
|
||||
|
||||
@Value("${octopus.message.init_from_server_key}")
|
||||
public String INIT_FROM_SERVER_KEY;
|
||||
|
||||
@Value("${octopus.message.init_to_server_key}")
|
||||
public String INIT_TO_SERVER_KEY;
|
||||
|
||||
@Bean
|
||||
public DirectExchange initDirectExchange() {
|
||||
return new DirectExchange(INIT_EXCHANGE);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue initFromServerQueue() {
|
||||
return new Queue(INIT_FROM_SERVER);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置一个队列和交换机的绑定
|
||||
*
|
||||
* @param initDirectQueue : 需要绑定的队列对象,参数名必须和某个@Bean的方法名完全相同,这样就会进行自动注入,对应 .bind()
|
||||
* @param initDirectExchange : 需要绑定的交换机对象,参数名必须和某个@Bean的方法名完全相同,这样就会进行自动注入,对应 .to()
|
||||
* .with() 方法对应的RoutingKey
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Binding initBinding(DirectExchange initDirectExchange, Queue initFromServerQueue) {
|
||||
return BindingBuilder.bind(initFromServerQueue).to(initDirectExchange).with(INIT_FROM_SERVER_KEY);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user