package com.ywt.alipaympapi.core.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 {
    @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).build();
    }

}
