SHARE
TWEET

Untitled

sleipnir1981 Oct 21st, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. info!("Start CloudState gRPC in 0.0.0.0:{}", opts.server_port);
  2.                 Server::builder()
  3.                     .serve(
  4.                         addr,
  5.                         Router {
  6.                             entity_discovery: Arc::new(EntityDiscoveryServer::new(discover))
  7.                         })
  8.                     .await
  9.                     .map_err(|err| error!("Error during start server phase: {:?}", err))
  10.                     .ok();
  11.  
  12.  
  13. And my service implementation is:
  14. use crate::protocol::spec::{
  15.         server::{EntityDiscovery, EntityDiscoveryServer},
  16.         ProxyInfo, EntitySpec, ServiceInfo, Entity,UserFunctionError,
  17.     };
  18.  
  19.     use crate::protocol::router::Router;
  20.  
  21.     pub struct Discover {
  22.         pub opts: Options,
  23.     }
  24.  
  25.     #[tonic::async_trait]
  26.     impl EntityDiscovery for Discover {
  27.  
  28.         async fn discover(
  29.             &self,
  30.             request: Request<ProxyInfo>,
  31.         ) -> Result<Response<EntitySpec>, Status> {
  32.  
  33.             let metadata = request.metadata();
  34.             let proxy_info: &ProxyInfo = request.get_ref();
  35.  
  36.             debug!("Received discovery call from sidecar with Metadata [{:?}", metadata );
  37.             info!("Received discovery call from sidecar [{:?} {:?}] supporting CloudState {:?}.{:?}", proxy_info.proxy_name, proxy_info.proxy_version, proxy_info.protocol_major_version, proxy_info.protocol_minor_version);
  38.             info!("Supported sidecar entity types: {:?}", proxy_info.supported_entity_types);
  39.  
  40.             let entity = Entity {
  41.                 entity_type: self.opts.entity_type.to_string(),
  42.                 service_name: self.opts.service_name.to_string(),
  43.                 persistence_id: self.opts.persistence_id.to_string(),
  44.             };
  45.  
  46.             let vec_entities = vec![entity];
  47.  
  48.             let lib_name: String = "cloudstate-rust-support".to_string();
  49.             let lib_version: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
  50.            let runtime = "rustc ".to_owned() + &version().unwrap().to_string();
  51.  
  52.            let info = ServiceInfo {
  53.                service_name: self.opts.service_name.to_string(),
  54.                service_version: self.opts.service_version.to_string(),
  55.                service_runtime: runtime,
  56.                support_library_name: lib_name,
  57.                support_library_version: lib_version.unwrap_or("0.0.1").to_string(),
  58.            };
  59.  
  60.            /*FileDescriptorSet{
  61.                file: vec![]
  62.            }*/
  63.  
  64.            let reply = EntitySpec {
  65.                proto: vec![],
  66.                entities: vec_entities,
  67.                service_info: Some(info),
  68.            };
  69.  
  70.            Ok(Response::new(reply))
  71.        }
  72.  
  73.        // Handle Sidecar Errors Messages
  74.        async fn report_error(
  75.            &self,
  76.            request: Request<UserFunctionError>,
  77.        ) -> Result<Response<()>, Status> {
  78.  
  79.            let metadata = request.metadata();
  80.            let user_func_error: &UserFunctionError = request.get_ref();
  81.  
  82.            debug!("Receive request for report_error. Metadata: {:?}", metadata );
  83.            error!("Received report_error from sidecar. Error: {:?}", user_func_error.message);
  84.            Ok(Response::new(()))
  85.        }
  86.  
  87.    }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top