https://blog.csdn.net/csdnsjg/article/details/80152815html
https://jingyan.baidu.com/article/219f4bf798e0cfde442d3831.htmljava
相似spring 、 maven 這類插件,須要再eclipse中提早安裝;spring
一、首先下載eclipse 對應的spring 的版本,查看eclipse 版本在 help-- about eclipse 中sql
二、找到打開eclipse,選擇 "Help" --> "Install New Software" --> "add" -->"Archive" --> 選擇剛纔下載好的springsource-tool-suite 「打開」--> "OK"apache
三、查看是否安裝成功,點擊「Window」--> "Preferences"查看是否安裝成功json
配置好後,新建spring 調用jsf 接口:api
一、 file --- new -- spring starter project app
二、maven 依賴配置添加,在pom.xml 中,能夠依照官方的xml文檔,只須要添加須要的依賴便可eclipse
三、在spring 項目下面,新建源文件,裏面包含log4j.xml 和 jsf-consumer.xml 也是依據官方的文檔進行修改,傳入參數改稱須要的便可maven
四、而後修改接口調用函數,導入相關的包,這裏採用spring集成的方式調用接口
五、參考以下:
package com.example.demo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.jd.erqing.application.jsf.VenderInfoService; import com.jd.fastjson.JSONObject; public class DemoApplicationTests { /** * SLF4J logger */ private final static Logger LOGGER = LoggerFactory.getLogger(DemoApplicationTests.class); /** * Method Name main * * @param args Return Type void */ public static void main(String[] args) { ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext("/jsf-consumer.xml"); VenderInfoService service = (VenderInfoService) appContext.getBean("venderInfoService"); while (true) { try { long start = System.currentTimeMillis(); String result = service.venderDownAmountList("10021"); long end = System.currentTimeMillis(); System.out.println("耗時:"+(end - start)); System.out.println(result); LOGGER.info("response msg from server :{}", result); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } try { Thread.sleep(2000); } catch (Exception e) { } } } }
還有使用API的方式(不依賴spring)調用JSF服務的方式。
實例以下:
package com.example.demo; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.spark.api.java.JavaRDD; import org.apache.spark.sql.Dataset; import org.apache.spark.sql.Row; import org.apache.spark.sql.SparkSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.jd.erqing.application.jsf.VenderInfoService; import com.jd.fastjson.JSONObject; import com.jd.jsf.gd.config.ConsumerConfig; import com.jd.jsf.gd.config.RegistryConfig; public class DemoApplication { /** * SLF4J logger */ private final static Logger LOGGER = LoggerFactory.getLogger(DemoApplication.class); /** * Method Name main * * @param args Return Type void */ public static void main(String[] args) { // // 引入傑夫接口 // ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext("/jsf-consumer.xml"); // VenderInfoService service = (VenderInfoService) appContext.getBean("venderInfoService"); RegistryConfig jsfRegistry = new RegistryConfig(); jsfRegistry.setIndex("i.jsf.jd.com"); LOGGER.info("實例RegistryConfig"); // 服務提供者鏈接註冊中心,設置屬性 ConsumerConfig<VenderInfoService> consumerConfig = new ConsumerConfig<VenderInfoService>(); consumerConfig.setInterfaceId("XXXXXXXXXXXXXXXXXXXXXXXXX"); // consumerConfig.setAlias("XXXXXXXXXXXXXXXXX"); // 線下 consumerConfig.setAlias("XXXXXXXXXXXXXXXXXXXX"); //線上 consumerConfig.setProtocol("jsf"); Map<String,String> parameter = new HashMap(); parameter.put(".token", "XXXXXXXXXXXXXXXXXXXX"); // parameter.put("hide", "true"); consumerConfig.setParameters(parameter); // 若是外面已經有xml配的註冊中心,使用consumerConfig.setRegistry(RegistryFactory.getRegistryConfigs()); consumerConfig.setRegistry(jsfRegistry); LOGGER.info("實例ConsumerConfig"); VenderInfoService service = consumerConfig.refer(); LOGGER.info("獲得調用端代理:{}", service); // // 讀入店鋪id數據 // SparkSession spark = SparkSession.builder().appName("demo_spark").enableHiveSupport().getOrCreate(); // spark.sql("insert overwrite table dev.dev_spark_demo_temp partition (dt = '2019-08-08') select pop_vender_id, sale_ord_id from app.app_sjzt_payout_apply_with_order where dt = '2019-08-05'"); // Dataset<Row> vender_set = spark.sql("select pop_vender_id from app.app_sjzt_payout_apply_with_order where dt = '2019-08-05' limit 2000"); // // // 將數據去重,轉換成 List<Row> 格式 // vender_set = vender_set.distinct(); // vender_set = vender_set.na().fill(0L); // JavaRDD<Row> vender= vender_set.toJavaRDD(); // List<Row> vender_list = vender.collect(); // // // 遍歷商家id,調用jsf接口 // for(Row row:vender_list) { // String id = row.getString(0); // String result = service.venderDownAmountList(id); // System.out.print(id + " "+ result + "\n"); // } // // System.out.println( "Hello World!" ); while (true) { try { long start = System.currentTimeMillis(); String result = service.venderDownAmountList("10021"); long end = System.currentTimeMillis(); System.out.println("耗時:"+(end - start)); System.out.println(result); LOGGER.info("response msg from server :{}", result); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } try { Thread.sleep(2000); } catch (Exception e) { } } } }