package com.ywt.mg.configs;

import io.grpc.Channel;
import io.grpc.ManagedChannelBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class GrpcChannelBeans {

    private final int maxInboundMessageSize = 1024*1024*256;

    @Value("${service.agent.grpc.addr}")
    private String agentAddr;

    @Bean(name = "agentChannel")
    public Channel getAgentChannel() {
        String[] hostAndPort = agentAddr.split(":");
        return ManagedChannelBuilder.forAddress(hostAndPort[0], Integer.parseInt(hostAndPort[1])).usePlaintext(true)
                .maxInboundMessageSize(maxInboundMessageSize).build();
//        return ManagedChannelBuilder.forAddress(hostAndPort[0], Integer.parseInt(hostAndPort[1])).usePlaintext(true).build();
    }


}
