├── .idea ├── compiler.xml ├── encodings.xml ├── libraries │ ├── Maven__cglib_cglib_nodep_3_2_4.xml │ ├── Maven__ch_qos_logback_logback_classic_1_1_11.xml │ ├── Maven__ch_qos_logback_logback_core_1_1_11.xml │ ├── Maven__com_101tec_zkclient_0_9.xml │ ├── Maven__com_alibaba_fastjson_1_2_38.xml │ ├── Maven__com_esotericsoftware_kryo_3_0_3.xml │ ├── Maven__com_esotericsoftware_minlog_1_3_0.xml │ ├── Maven__com_esotericsoftware_reflectasm_1_10_1.xml │ ├── Maven__com_espertech_esper_6_1_0.xml │ ├── Maven__com_fasterxml_classmate_1_3_1.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_annotations_2_6_0.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_core_2_6_3.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_databind_2_6_3.xml │ ├── Maven__com_google_code_gson_gson_2_8_1.xml │ ├── Maven__com_google_guava_guava_18_0.xml │ ├── Maven__com_googlecode_json_simple_json_simple_1_1.xml │ ├── Maven__com_lmax_disruptor_3_3_2.xml │ ├── Maven__com_yammer_metrics_metrics_core_2_2_0.xml │ ├── Maven__commons_codec_commons_codec_1_6.xml │ ├── Maven__commons_io_commons_io_2_5.xml │ ├── Maven__commons_lang_commons_lang_2_5.xml │ ├── Maven__dom4j_dom4j_1_6.xml │ ├── Maven__io_netty_netty_3_7_0_Final.xml │ ├── Maven__javax_activation_activation_1_1.xml │ ├── Maven__javax_mail_mail_1_4.xml │ ├── Maven__javax_servlet_servlet_api_2_5.xml │ ├── Maven__javax_validation_validation_api_1_1_0_Final.xml │ ├── Maven__javax_xml_bind_jaxb_api_2_2_11.xml │ ├── Maven__jline_jline_0_9_94.xml │ ├── Maven__log4j_log4j_1_2_15.xml │ ├── Maven__net_jpountz_lz4_lz4_1_3_0.xml │ ├── Maven__net_sf_jopt_simple_jopt_simple_4_9.xml │ ├── Maven__org_antlr_antlr4_runtime_4_5_3.xml │ ├── Maven__org_apache_commons_commons_lang3_3_3_1.xml │ ├── Maven__org_apache_commons_commons_pool2_2_4_2.xml │ ├── Maven__org_apache_curator_curator_client_2_12_0.xml │ ├── Maven__org_apache_curator_curator_framework_2_12_0.xml │ ├── Maven__org_apache_kafka_kafka_2_10_0_10_1_0.xml │ ├── Maven__org_apache_kafka_kafka_clients_0_10_1_0.xml │ ├── Maven__org_apache_logging_log4j_log4j_api_2_8.xml │ ├── Maven__org_apache_logging_log4j_log4j_core_2_8.xml │ ├── Maven__org_apache_logging_log4j_log4j_slf4j_impl_2_8.xml │ ├── Maven__org_apache_storm_storm_core_1_1_0.xml │ ├── Maven__org_apache_storm_storm_kafka_1_1_0.xml │ ├── Maven__org_apache_storm_storm_redis_1_1_0.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_23.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_el_8_5_23.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_23.xml │ ├── Maven__org_apache_tomcat_tomcat_annotations_api_8_5_23.xml │ ├── Maven__org_apache_zookeeper_zookeeper_3_4_8.xml │ ├── Maven__org_clojure_clojure_1_7_0.xml │ ├── Maven__org_hibernate_hibernate_validator_5_3_5_Final.xml │ ├── Maven__org_jboss_logging_jboss_logging_3_3_0_Final.xml │ ├── Maven__org_objenesis_objenesis_2_1.xml │ ├── Maven__org_ow2_asm_asm_5_0_3.xml │ ├── Maven__org_scala_lang_scala_library_2_10_6.xml │ ├── Maven__org_slf4j_jcl_over_slf4j_1_7_25.xml │ ├── Maven__org_slf4j_jul_to_slf4j_1_7_25.xml │ ├── Maven__org_slf4j_log4j_over_slf4j_1_6_6.xml │ ├── Maven__org_slf4j_slf4j_api_1_7_21.xml │ ├── Maven__org_springframework_boot_spring_boot_1_5_8_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_autoconfigure_1_5_8_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_1_5_8_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_logging_1_5_8_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_tomcat_1_5_8_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_web_1_5_8_RELEASE.xml │ ├── Maven__org_springframework_integration_spring_integration_core_4_3_12_RELEASE.xml │ ├── Maven__org_springframework_integration_spring_integration_kafka_2_1_2_RELEASE.xml │ ├── Maven__org_springframework_kafka_spring_kafka_1_2_3_RELEASE.xml │ ├── Maven__org_springframework_retry_spring_retry_1_1_3_RELEASE.xml │ ├── Maven__org_springframework_spring_aop_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_beans_4_3_12_RELEASE.xml │ ├── Maven__org_springframework_spring_context_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_core_4_3_12_RELEASE.xml │ ├── Maven__org_springframework_spring_expression_4_3_12_RELEASE.xml │ ├── Maven__org_springframework_spring_messaging_4_3_10_RELEASE.xml │ ├── Maven__org_springframework_spring_tx_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_web_4_3_12_RELEASE.xml │ ├── Maven__org_springframework_spring_webmvc_4_3_12_RELEASE.xml │ ├── Maven__org_xerial_snappy_snappy_java_1_1_2_6.xml │ ├── Maven__org_yaml_snakeyaml_1_17.xml │ ├── Maven__redis_clients_jedis_2_8_1.xml │ ├── Maven__ring_cors_ring_cors_0_1_5.xml │ └── Maven__xml_apis_xml_apis_1_0_b2.xml ├── misc.xml └── modules.xml ├── README.md ├── SpringBootKafka.iml ├── pom.xml └── src ├── main ├── java │ ├── Controller │ │ ├── KafkaSendController.java │ │ └── ResultCode.java │ ├── config │ │ ├── KafkaConsumerConfig.java │ │ └── SenderConfig.java │ ├── event │ │ ├── ContextPropertiesListener.java │ │ ├── ContextPropertiesTest.java │ │ └── PersonEvent.java │ ├── kafka │ │ ├── KafkaConsumer.java │ │ ├── SimpleProducer.java │ │ └── SpringBootKafkaApplication.java │ ├── log │ │ ├── Handler.java │ │ ├── LogParse.java │ │ ├── LogParse2.java │ │ └── ParseXML.java │ ├── model │ │ ├── AcceptSysHeadData.java │ │ ├── AcceptSysHeadStructData.java │ │ ├── AcceptXMLService.java │ │ ├── BodyData.java │ │ ├── BodyDataArray.java │ │ ├── BodyDataArrayData.java │ │ ├── BodyDataArrayDataField.java │ │ ├── BodyDataField.java │ │ ├── ReturnAppHeadData.java │ │ ├── ReturnLocalHeadData.java │ │ ├── ReturnSysHeadData.java │ │ ├── ReturnSysHeadStructData.java │ │ ├── ReturnXMLService.java │ │ ├── SubOrder.java │ │ ├── SysHeadStructDataArray.java │ │ ├── SysHeadStructDataArrayData.java │ │ ├── SysHeadStructDataArrayDataField.java │ │ ├── SysHeadStructDataField.java │ │ └── Traveler.java │ ├── pojo │ │ ├── AppCardInfo.java │ │ └── MessageToRedis.java │ ├── utils │ │ ├── DataType.java │ │ └── JaxbUtil.java │ └── window │ │ ├── LogRuleBlot.java │ │ ├── RedisStoreBlot.java │ │ ├── RuleBlot.java │ │ ├── SlidingWindowBolt.java │ │ └── SlidingWindowTopology.java └── resources │ ├── application.properties │ ├── cardFile.xml │ ├── cardInfo.drl │ └── log4j.properties └── test ├── java ├── StringTest.java ├── drools │ ├── DroolsTester.java │ └── User.java └── trident │ └── StromTrident.java └── resources └── Sample.drl /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__cglib_cglib_nodep_3_2_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__ch_qos_logback_logback_classic_1_1_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__ch_qos_logback_logback_core_1_1_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_101tec_zkclient_0_9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_alibaba_fastjson_1_2_38.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_esotericsoftware_kryo_3_0_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_esotericsoftware_minlog_1_3_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_esotericsoftware_reflectasm_1_10_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_espertech_esper_6_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_classmate_1_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_6_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_6_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_6_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_code_gson_gson_2_8_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_guava_guava_18_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_lmax_disruptor_3_3_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_yammer_metrics_metrics_core_2_2_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_codec_commons_codec_1_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_io_commons_io_2_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_lang_commons_lang_2_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__dom4j_dom4j_1_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_netty_netty_3_7_0_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_activation_activation_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_mail_mail_1_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_servlet_servlet_api_2_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_validation_validation_api_1_1_0_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_xml_bind_jaxb_api_2_2_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__jline_jline_0_9_94.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__log4j_log4j_1_2_15.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_jpountz_lz4_lz4_1_3_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_sf_jopt_simple_jopt_simple_4_9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_antlr_antlr4_runtime_4_5_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_commons_commons_lang3_3_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_commons_commons_pool2_2_4_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_curator_curator_client_2_12_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_curator_curator_framework_2_12_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_kafka_kafka_2_10_0_10_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_kafka_kafka_clients_0_10_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_logging_log4j_log4j_api_2_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_logging_log4j_log4j_core_2_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_logging_log4j_log4j_slf4j_impl_2_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_storm_storm_core_1_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_storm_storm_kafka_1_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_storm_storm_redis_1_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_23.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_el_8_5_23.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_23.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_tomcat_annotations_api_8_5_23.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_zookeeper_zookeeper_3_4_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_clojure_clojure_1_7_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_hibernate_validator_5_3_5_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_3_0_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_objenesis_objenesis_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_ow2_asm_asm_5_0_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_scala_lang_scala_library_2_10_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_jcl_over_slf4j_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_log4j_over_slf4j_1_6_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_21.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_1_5_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_1_5_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_1_5_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_logging_1_5_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_tomcat_1_5_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_web_1_5_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_integration_spring_integration_core_4_3_12_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_integration_spring_integration_kafka_2_1_2_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_kafka_spring_kafka_1_2_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_retry_spring_retry_1_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aop_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_beans_4_3_12_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_core_4_3_12_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_expression_4_3_12_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_messaging_4_3_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_tx_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_web_4_3_12_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_webmvc_4_3_12_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_xerial_snappy_snappy_java_1_1_2_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__redis_clients_jedis_2_8_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__ring_cors_ring_cors_0_1_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__xml_apis_xml_apis_1_0_b2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpringBootKafka 2 | Strom 实时风控统计 3 | 4 | 处理流程 5 | 1.实时解析日志报文,并把解析后的日志推送到kafka当中 6 | 7 | 2.storm从kafka中读取数据,并根据实时统计和计算 8 | 9 | 规则: 10 | 1.消费金额(一天内的消费金额不能>2W)如果累计消费大于额度,进行短信或者电话确认 11 | 2.登录地点异常预警(如上次根据IP得到的登录地点为北京,这次登录的地点为上海)此种情况应该给予推送或者重新发短信确认 12 | -------------------------------------------------------------------------------- /SpringBootKafka.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | file://$MODULE_DIR$/src/main/resources/producer-context.xml 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.sprinKafka.cn 8 | SpringBootKafka 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 1.5.8.RELEASE 13 | 14 | 15 | 16 | 17 | org.apache.storm 18 | storm-kafka 19 | 1.1.0 20 | 21 | 22 | zookeeper 23 | org.apache.zookeeper 24 | 25 | 26 | 27 | 28 | 29 | org.apache.storm 30 | storm-core 31 | 1.1.0 32 | provided 33 | 34 | 35 | org.apache.storm 36 | storm-redis 37 | 1.1.0 38 | 39 | 40 | 41 | 42 | com.google.code.gson 43 | gson 44 | 2.8.1 45 | 46 | 47 | 48 | 49 | org.apache.commons 50 | commons-lang3 51 | 3.3.1 52 | 53 | 54 | 55 | 56 | javax.xml.bind 57 | jaxb-api 58 | 2.2.11 59 | 60 | 61 | 62 | org.apache.kafka 63 | kafka_2.10 64 | 0.10.1.0 65 | 66 | 67 | slf4j-log4j12 68 | org.slf4j 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.apache.kafka 76 | kafka-clients 77 | 0.10.1.0 78 | 79 | 80 | 81 | 82 | 83 | dom4j 84 | dom4j 85 | 1.6 86 | 87 | 88 | 89 | org.springframework.integration 90 | spring-integration-kafka 91 | 2.1.2.RELEASE 92 | 93 | 94 | 95 | com.espertech 96 | esper 97 | 6.1.0 98 | 99 | 100 | 101 | 102 | org.springframework.boot 103 | spring-boot-starter 104 | ${springBoot.version} 105 | 106 | 107 | 108 | org.springframework.boot 109 | spring-boot-starter-web 110 | ${springBoot.version} 111 | 112 | 113 | 114 | com.alibaba 115 | fastjson 116 | 1.2.38 117 | 118 | 119 | 120 | org.springframework.boot 121 | spring-boot-starter-tomcat 122 | ${springBoot.version} 123 | 124 | 125 | 126 | org.springframework.kafka 127 | spring-kafka 128 | 1.2.3.RELEASE 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | org.apache.maven.plugins 138 | maven-assembly-plugin 139 | 2.3 140 | 141 | false 142 | 143 | jar-with-dependencies 144 | 145 | 146 | 147 | com.think.TestMain 148 | 149 | 150 | 151 | 152 | 153 | make-assembly 154 | package 155 | 156 | assembly 157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /src/main/java/Controller/KafkaSendController.java: -------------------------------------------------------------------------------- 1 | package Controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.kafka.core.KafkaTemplate; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import javax.xml.ws.Response; 15 | 16 | @RestController 17 | public class KafkaSendController { 18 | Logger logger= LoggerFactory.getLogger(KafkaSendController.class); 19 | 20 | @Autowired 21 | private KafkaTemplate kafkaTemplate; 22 | 23 | @RequestMapping(value ="/send",method = RequestMethod.POST) 24 | @ResponseBody 25 | public void sendKafka(HttpServletRequest request, HttpServletResponse response) { 26 | try { 27 | String message = request.getParameter("message"); 28 | logger.info("kafka的消息={}",message); 29 | kafkaTemplate.send("testTopic", "key", message); 30 | logger.info("发送kafka成功."); 31 | } catch (Exception e) { 32 | logger.error("发送kafka失败", e); 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/main/java/Controller/ResultCode.java: -------------------------------------------------------------------------------- 1 | package Controller; 2 | 3 | public enum ResultCode { 4 | SUCESSS, 5 | EXCEPTION 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/config/KafkaConsumerConfig.java: -------------------------------------------------------------------------------- 1 | package config; 2 | 3 | import org.apache.kafka.clients.consumer.ConsumerConfig; 4 | import org.apache.kafka.common.serialization.StringDeserializer; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; 8 | import org.springframework.kafka.core.ConsumerFactory; 9 | import org.springframework.kafka.core.DefaultKafkaConsumerFactory; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public class KafkaConsumerConfig { 15 | 16 | @Value("${spring.kafka.bootstrap-servers}") 17 | private String bootstrapServers; 18 | 19 | @Value("${kafka.topic.basictopic}") 20 | private String topic; 21 | 22 | @Bean 23 | public ConsumerFactory consumerFactory() { 24 | Map configProps = new HashMap(); 25 | configProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); 26 | configProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); 27 | configProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); 28 | configProps.put(ConsumerConfig.GROUP_ID_CONFIG, topic); 29 | return new DefaultKafkaConsumerFactory(configProps); 30 | } 31 | 32 | @Bean 33 | public ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory() { 34 | ConcurrentKafkaListenerContainerFactory factory = 35 | new ConcurrentKafkaListenerContainerFactory(); 36 | factory.setConsumerFactory(consumerFactory()); 37 | 38 | return factory; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/config/SenderConfig.java: -------------------------------------------------------------------------------- 1 | package config; 2 | 3 | import org.apache.kafka.clients.producer.ProducerConfig; 4 | import org.apache.kafka.clients.producer.internals.Sender; 5 | import org.apache.kafka.common.serialization.StringSerializer; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; 10 | import org.springframework.kafka.core.KafkaTemplate; 11 | import org.springframework.kafka.core.ProducerFactory; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | @Configuration 17 | public class SenderConfig { 18 | 19 | @Value("${spring.kafka.bootstrap-servers}") 20 | private String bootstrapServers; 21 | 22 | @Bean 23 | public ProducerFactory producerFactory() { 24 | Map configProps = new HashMap(); 25 | configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); 26 | configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); 27 | configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); 28 | 29 | return new DefaultKafkaProducerFactory(configProps); 30 | 31 | 32 | 33 | } 34 | 35 | @Bean 36 | public KafkaTemplate kafkaTemplate() { 37 | return new KafkaTemplate(producerFactory()); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/event/ContextPropertiesListener.java: -------------------------------------------------------------------------------- 1 | package event; 2 | 3 | import com.espertech.esper.client.EventBean; 4 | import com.espertech.esper.client.UpdateListener; 5 | 6 | public class ContextPropertiesListener implements UpdateListener { 7 | public void update(EventBean[] newEvents, EventBean[] oldEvents) { 8 | 9 | if (newEvents != null) 10 | { 11 | EventBean event = newEvents[0]; 12 | System.out.println("Average Price: " + event.get("cast(avg(price), int)") + ", DataType is " 13 | + event.get("cast(avg(price), int)").getClass().getName()); 14 | } 15 | } 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/main/java/event/ContextPropertiesTest.java: -------------------------------------------------------------------------------- 1 | package event; 2 | 3 | import com.espertech.esper.client.*; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | public class ContextPropertiesTest { 8 | 9 | private static Logger logger= LoggerFactory.getLogger(ContextPropertiesTest.class); 10 | public static void main(String[] args) 11 | { 12 | EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(); 13 | EPAdministrator admin = epService.getEPAdministrator(); 14 | EPRuntime runtime = epService.getEPRuntime(); 15 | 16 | String personEvent=PersonEvent.class.getName(); 17 | logger.info("---personEvent---:"+personEvent); 18 | 19 | String epl1="select cast(avg(price),int) from PersonEvent.win.length_batch(2)"; 20 | String epl2="select avg(price) from "+ personEvent +".win.length_batch(2)"; 21 | 22 | EPStatement statementState=admin.createEPL(epl1); 23 | statementState.addListener(new ContextPropertiesListener()); 24 | 25 | PersonEvent p1=new PersonEvent(); 26 | p1.setPrice(10); 27 | runtime.sendEvent(p1); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/event/PersonEvent.java: -------------------------------------------------------------------------------- 1 | package event; 2 | 3 | public class PersonEvent { 4 | 5 | private int id; 6 | private int price; 7 | 8 | public int getId() 9 | { 10 | return id; 11 | } 12 | 13 | public void setId(int id) 14 | { 15 | this.id = id; 16 | } 17 | 18 | public int getPrice() 19 | { 20 | return price; 21 | } 22 | 23 | public void setPrice(int price) 24 | { 25 | this.price = price; 26 | } 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/kafka/KafkaConsumer.java: -------------------------------------------------------------------------------- 1 | package kafka; 2 | 3 | import org.apache.kafka.clients.consumer.ConsumerRecord; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.kafka.annotation.KafkaListener; 7 | 8 | public class KafkaConsumer { 9 | 10 | Logger logger= LoggerFactory.getLogger(KafkaConsumer.class); 11 | 12 | /** 13 | * KafkaLinser监听 14 | * @param record 15 | */ 16 | @KafkaListener(topics = {"testTopic"}) 17 | public void listen(ConsumerRecord record) { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/kafka/SimpleProducer.java: -------------------------------------------------------------------------------- 1 | package kafka; 2 | 3 | import org.apache.kafka.clients.producer.*; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import java.text.SimpleDateFormat; 8 | import java.util.Properties; 9 | 10 | public class SimpleProducer { 11 | 12 | static Logger logger= LoggerFactory.getLogger(SimpleProducer.class); 13 | 14 | public static void sedMessage(String str){ 15 | Properties props = new Properties(); 16 | props.put("bootstrap.servers", "10.1.69.11:6667"); 17 | props.put("acks", "all"); 18 | props.put("retries", 0); 19 | props.put("batch.size", 16384); 20 | props.put("linger.ms", 1); 21 | props.put("buffer.memory", 33554432); 22 | props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); 23 | props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); 24 | props.put(ProducerConfig.METADATA_FETCH_TIMEOUT_CONFIG, "3000"); 25 | KafkaProducer producer = new KafkaProducer(props); 26 | 27 | ProducerRecord record = new ProducerRecord("stormKafka", str); 28 | producer.send(record , 29 | new Callback() { 30 | public void onCompletion(RecordMetadata metadata, Exception e) { 31 | if(e != null) 32 | e.printStackTrace(); 33 | System.out.println("Partition:"+metadata.partition()+" The offset of the record we just sent is: " + metadata.offset()); 34 | logger.info("Partition:"+metadata.partition()+" The offset of the record we just sent is: " + metadata.offset()); 35 | } 36 | }); 37 | producer.close(); 38 | } 39 | 40 | public static void main(String []args){ 41 | sedMessage(""); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/kafka/SpringBootKafkaApplication.java: -------------------------------------------------------------------------------- 1 | package kafka; 2 | 3 | 4 | import Controller.KafkaSendController; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class SpringBootKafkaApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(KafkaSendController.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/log/LogParse.java: -------------------------------------------------------------------------------- 1 | package log; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import kafka.SimpleProducer; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import java.io.File; 8 | import java.io.FileNotFoundException; 9 | import java.io.IOException; 10 | import java.io.RandomAccessFile; 11 | import java.text.SimpleDateFormat; 12 | import java.util.Date; 13 | import java.util.Map; 14 | 15 | public class LogParse implements Runnable{ 16 | 17 | static Logger logger= LoggerFactory.getLogger(LogParse.class); 18 | private File logFile = null; 19 | private long lastTimeFileSize = 0; // ?????? 20 | private static SimpleDateFormat dateFormat = new SimpleDateFormat( 21 | "yyyy-MM-dd HH:mm:ss"); 22 | 23 | public LogParse(File logFile) { 24 | this.logFile = logFile; 25 | lastTimeFileSize = logFile.length(); 26 | } 27 | 28 | /** 29 | * 30 | */ 31 | public void run() { 32 | while (true) { 33 | try { 34 | long len = logFile.length(); 35 | if (len < lastTimeFileSize) { 36 | System.out.println("Log file was reset. Restarting logging from start of file."); 37 | lastTimeFileSize = len; 38 | } else if(len > lastTimeFileSize) { 39 | RandomAccessFile randomFile = new RandomAccessFile(logFile, "r"); 40 | randomFile.seek(lastTimeFileSize); 41 | String tmp = null; 42 | while ((tmp = randomFile.readLine()) != null) { 43 | String str=new String(tmp.getBytes("ISO8859-1")); 44 | int i=str.indexOf("组包报文"); 45 | if(-1!=i){ 46 | String subStr=str.substring(i+5,str.length()).trim(); 47 | logger.info(dateFormat.format(new Date()) + "\t" + subStr); 48 | Map jsonHashMap=ParseXML.parseAcceptXML(subStr); 49 | SimpleProducer.sedMessage(JSON.toJSONString(jsonHashMap)); 50 | logger.info(dateFormat.format(new Date()) + "\t" + JSON.toJSONString(jsonHashMap)); 51 | } 52 | System.out.println(dateFormat.format(new Date()) + "\t" + str); 53 | } 54 | lastTimeFileSize = randomFile.length(); 55 | randomFile.close(); 56 | } 57 | } catch (IOException e) { 58 | // TODO Auto-generated catch block 59 | logger.info(e.getMessage()); 60 | e.printStackTrace(); 61 | } 62 | 63 | try { 64 | Thread.sleep(50); 65 | } catch (InterruptedException e) { 66 | // TODO Auto-generated catch block 67 | e.printStackTrace(); 68 | } 69 | } 70 | } 71 | 72 | public static void main(String []args){ 73 | File logFile = new File("C:\\Users\\user\\Desktop\\BOD\\ECIS_LOGS\\out.log"); 74 | Thread wthread = new Thread(new LogParse(logFile)); 75 | wthread.start(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/log/LogParse2.java: -------------------------------------------------------------------------------- 1 | package log; 2 | 3 | import org.dom4j.Document; 4 | import org.dom4j.Element; 5 | import org.dom4j.io.SAXReader; 6 | import org.springframework.context.support.ClassPathXmlApplicationContext; 7 | 8 | import java.io.FileInputStream; 9 | import java.io.InputStream; 10 | import java.util.Iterator; 11 | 12 | public class LogParse2 { 13 | 14 | public static void main(String []args){ 15 | try{ 16 | //将src下面的xml转换为输入流 17 | InputStream inputStream = new FileInputStream("src/main/resources/cardFile.xml"); 18 | //创建SAXReader读取器,专门用于读取xml 19 | SAXReader saxReader = new SAXReader(); 20 | //根据saxReader的read重写方法可知,既可以通过inputStream输入流来读取,也可以通过file对象来读取 21 | Document document = saxReader.read(inputStream); 22 | 23 | Element rootElement = document.getRootElement(); 24 | Iterator modulesIterator = rootElement.elements("name").iterator(); 25 | //rootElement.element("name");获取某一个子元素 26 | //rootElement.elements("name");获取根节点下子元素moudule节点的集合,返回List集合类型 27 | //rootElement.elements("module").iterator();把返回的list集合里面每一个元素迭代子节点,全部返回到一个Iterator集合中 28 | while(modulesIterator.hasNext()){ 29 | Element moduleElement = modulesIterator.next(); 30 | Element nameElement = moduleElement.element("name"); 31 | System.out.println(nameElement.getName() + ":" + nameElement.getText()); 32 | Element valueElement = moduleElement.element("value"); 33 | System.out.println(valueElement.getName() + ":" + valueElement.getText()); 34 | Element descriptElement = moduleElement.element("descript"); 35 | System.out.println(descriptElement.getName() + ":" + descriptElement.getText()); 36 | } 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/log/ParseXML.java: -------------------------------------------------------------------------------- 1 | package log; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import model.*; 5 | import pojo.AppCardInfo; 6 | import utils.JaxbUtil; 7 | import utils.JaxbUtil.*; 8 | 9 | import java.util.*; 10 | 11 | public class ParseXML { 12 | 13 | 14 | public static Map parseAcceptXML(String xml) { 15 | 16 | Map resultMap= new HashMap(); 17 | Map sysHeaderMap = new HashMap(); 18 | 19 | AppCardInfo appCardInfo = new AppCardInfo(); 20 | 21 | String retCode = "000000"; 22 | StringBuffer retMsgBuffer = new StringBuffer(); 23 | 24 | JaxbUtil acceptBinder = new JaxbUtil(AcceptXMLService.class, CollectionWrapper.class); 25 | AcceptXMLService acceptXMLService = acceptBinder.fromXml(xml); 26 | 27 | if (acceptXMLService != null) { 28 | // 解析sys-header信息 29 | if(acceptXMLService.getAcceptSysHeadData()!=null){ 30 | List sysHeadDataList = acceptXMLService.getAcceptSysHeadData(); 31 | for (int i = 0; i < sysHeadDataList.size(); i++) { 32 | AcceptSysHeadData tmpSysHeadData = sysHeadDataList.get(i); 33 | if (tmpSysHeadData.getName().equals("SYS_HEAD")) { 34 | List sysHeadStructDataList = tmpSysHeadData.getSysHeadStructData(); 35 | for(int j = 0; j < sysHeadStructDataList.size(); j++){ 36 | AcceptSysHeadStructData tmpAcceptSysHeadStructData = sysHeadStructDataList.get(j); 37 | String tmpName = tmpAcceptSysHeadStructData.getName(); 38 | String tmpValue = tmpAcceptSysHeadStructData.getField().getValue(); 39 | if(tmpName.equals("SERVICE_CODE")){ 40 | sysHeaderMap.put("sysHeaderServiceCode", tmpValue); 41 | }else if(tmpName.equals("SEQ_NO")){ 42 | sysHeaderMap.put("seqNo", tmpValue); 43 | } 44 | } 45 | } 46 | } 47 | }else{ 48 | retCode = "000001"; 49 | retMsgBuffer.append("sys-header 为空;"); 50 | } 51 | // 解析body信息 52 | if(acceptXMLService.getBodyData()!=null){ 53 | List bodyDataList = acceptXMLService.getBodyData(); 54 | for(int j=0;j\n" + 130 | "\n" + 131 | " \n" + 132 | " \n" + 133 | " \n" + 134 | " \n" + 135 | " SVR_CARD\n" + 136 | " \n" + 137 | " \n" + 138 | " ONLINE\n" + 139 | " \n" + 140 | " \n" + 141 | " UC\n" + 142 | " \n" + 143 | " \n" + 144 | " 027001\n" + 145 | " \n" + 146 | " \n" + 147 | " EC0001\n" + 148 | " \n" + 149 | " \n" + 150 | " 20210917\n" + 151 | " \n" + 152 | " \n" + 153 | " 102648\n" + 154 | " \n" + 155 | " \n" + 156 | " 127.0.0.1\n" + 157 | " \n" + 158 | " \n" + 159 | " CHINESE\n" + 160 | " \n" + 161 | " \n" + 162 | " ECI2021091700071683\n" + 163 | " \n" + 164 | " \n" + 165 | " M\n" + 166 | " \n" + 167 | " \n" + 168 | " cups.gaps.zpk\n" + 169 | " \n" + 170 | " \n" + 171 | " RB\n" + 172 | " \n" + 173 | " \n" + 174 | " 1200\n" + 175 | " \n" + 176 | " \n" + 177 | " 6077\n" + 178 | " \n" + 179 | " \n" + 180 | " \n" + 181 | " \n" + 182 | " \n" + 183 | " \n" + 184 | " 6236430910100000052\n" + 185 | " \n" + 186 | " \n" + 187 | " 00110\n" + 188 | " \n" + 189 | " \n" + 190 | " 30122200000000661F\n" + 191 | " \n" + 192 | " \n" + 193 | " CNY\n" + 194 | " \n" + 195 | " \n" + 196 | " 11\n" + 197 | " \n" + 198 | " \n" + 199 | " 20211121\n" + 200 | " \n" + 201 | " \n" + 202 | " 92010000\n" + 203 | " \n" + 204 | " \n" + 205 | " 123456789012345\n" + 206 | " \n" + 207 | " \n" + 208 | " ASAO00215\n" + 209 | " \n" + 210 | " \n" + 211 | " 000006000600000000004012000\n" + 212 | " \n" + 213 | " \n" + 214 | " 1000\n" + 215 | " \n" + 216 | " \n" + 217 | " 000000016100\n" + 218 | " \n" + 219 | " \n" + 220 | ""; 221 | 222 | 223 | ParseXML parseXML=new ParseXML(); 224 | 225 | String subStr=str.substring(str.indexOf("组包报文")+5,str.length()).trim(); 226 | System.out.println("teh message is:"+subStr); 227 | 228 | HashMap hashMap= (HashMap) parseXML.parseAcceptXML(subStr); 229 | 230 | System.out.println(JSON.toJSONString(hashMap)); 231 | 232 | 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /src/main/java/model/AcceptSysHeadData.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import java.util.List; 4 | 5 | import javax.xml.bind.annotation.XmlAttribute; 6 | import javax.xml.bind.annotation.XmlElement; 7 | import javax.xml.bind.annotation.XmlElementWrapper; 8 | 9 | public class AcceptSysHeadData { 10 | 11 | @XmlAttribute(name = "name") 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | 20 | private String name; 21 | 22 | @XmlElementWrapper(name = "struct") 23 | @XmlElement(name = "data") 24 | public List getSysHeadStructData() { 25 | return sysHeadStructData; 26 | } 27 | 28 | public void setSysHeadStructData(List sysHeadStructData) { 29 | this.sysHeadStructData = sysHeadStructData; 30 | } 31 | 32 | private List sysHeadStructData; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/model/AcceptSysHeadStructData.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import javax.xml.bind.annotation.XmlAttribute; 4 | import javax.xml.bind.annotation.XmlElement; 5 | 6 | public class AcceptSysHeadStructData { 7 | 8 | @XmlAttribute(name = "name") 9 | public String getName() { 10 | return name; 11 | } 12 | 13 | public void setName(String name) { 14 | this.name = name; 15 | } 16 | 17 | private String name; 18 | 19 | @XmlElement(name = "field") 20 | public SysHeadStructDataField getField() { 21 | return field; 22 | } 23 | 24 | public void setField(SysHeadStructDataField field) { 25 | this.field = field; 26 | } 27 | 28 | private SysHeadStructDataField field; 29 | 30 | // @XmlElement(name = "array") 31 | // public SysHeadStructDataArray getSysHeadStructDataArray() { 32 | // return sysHeadStructDataArray; 33 | // } 34 | // 35 | // public void setSysHeadStructDataArray(SysHeadStructDataArray sysHeadStructDataArray) { 36 | // this.sysHeadStructDataArray = sysHeadStructDataArray; 37 | // } 38 | // 39 | // private SysHeadStructDataArray sysHeadStructDataArray; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/model/AcceptXMLService.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import java.util.List; 4 | 5 | import javax.xml.bind.annotation.XmlElement; 6 | import javax.xml.bind.annotation.XmlElementWrapper; 7 | import javax.xml.bind.annotation.XmlRootElement; 8 | 9 | @XmlRootElement(name = "service") 10 | public class AcceptXMLService { 11 | 12 | @XmlElementWrapper(name = "sys-header") 13 | @XmlElement(name = "data") 14 | public List getAcceptSysHeadData() { 15 | return acceptSysHeadData; 16 | } 17 | 18 | public void setAcceptSysHeadData(List acceptSysHeadData) { 19 | this.acceptSysHeadData = acceptSysHeadData; 20 | } 21 | private List acceptSysHeadData; 22 | 23 | @XmlElementWrapper(name = "body") 24 | @XmlElement(name = "data") 25 | public List getBodyData() { 26 | return bodyData; 27 | } 28 | 29 | public void setBodyData(List bodyData) { 30 | this.bodyData = bodyData; 31 | } 32 | 33 | private List bodyData; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/model/BodyData.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import java.util.List; 4 | 5 | import javax.xml.bind.annotation.XmlAttribute; 6 | import javax.xml.bind.annotation.XmlElement; 7 | import javax.xml.bind.annotation.XmlElementWrapper; 8 | 9 | public class BodyData { 10 | 11 | @XmlAttribute(name = "name") 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | 20 | private String name; 21 | 22 | @XmlElement(name = "field") 23 | public BodyDataField getField() { 24 | return field; 25 | } 26 | 27 | public void setField(BodyDataField field) { 28 | this.field = field; 29 | } 30 | 31 | private BodyDataField field; 32 | 33 | @XmlElement(name = "reason") 34 | public String[] getRefuseReason() { 35 | return refuseReason; 36 | } 37 | 38 | public void setRefuseReason(String[] refuseReason) { 39 | this.refuseReason = refuseReason; 40 | } 41 | 42 | private String[] refuseReason; 43 | 44 | @XmlElement(name = "array") 45 | public List getBodyDataArray() { 46 | return bodyDataArray; 47 | } 48 | 49 | public void setBodyDataArray(List bodyDataArray) { 50 | this.bodyDataArray = bodyDataArray; 51 | } 52 | 53 | private List bodyDataArray; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/model/BodyDataArray.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import java.util.List; 4 | 5 | import javax.xml.bind.annotation.XmlElement; 6 | import javax.xml.bind.annotation.XmlElementWrapper; 7 | 8 | public class BodyDataArray { 9 | 10 | @XmlElementWrapper(name = "struct") 11 | @XmlElement(name = "data") 12 | public List getBodyDataArrayData() { 13 | return bodyDataArrayData; 14 | } 15 | 16 | public void setBodyDataArrayData(List bodyDataArrayData) { 17 | this.bodyDataArrayData = bodyDataArrayData; 18 | } 19 | 20 | private List bodyDataArrayData; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/model/BodyDataArrayData.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import java.util.List; 4 | 5 | import javax.xml.bind.annotation.XmlAttribute; 6 | import javax.xml.bind.annotation.XmlElement; 7 | 8 | public class BodyDataArrayData { 9 | 10 | @XmlAttribute(name = "name") 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | private String name; 20 | 21 | @XmlElement(name = "field") 22 | public List getBodyDataArrayDataField() { 23 | return bodyDataArrayDataField; 24 | } 25 | 26 | public void setBodyDataArrayDataField(List bodyDataArrayDataField) { 27 | this.bodyDataArrayDataField = bodyDataArrayDataField; 28 | } 29 | 30 | private List bodyDataArrayDataField; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/model/BodyDataArrayDataField.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import javax.xml.bind.annotation.XmlAttribute; 4 | import javax.xml.bind.annotation.XmlValue; 5 | 6 | public class BodyDataArrayDataField { 7 | 8 | @XmlAttribute(name = "scale") 9 | public String getScale() { 10 | return scale; 11 | } 12 | public void setScale(String scale) { 13 | this.scale = scale; 14 | } 15 | private String scale; 16 | 17 | @XmlAttribute(name = "length") 18 | public String getLength() { 19 | return length; 20 | } 21 | public void setLength(String length) { 22 | this.length = length; 23 | } 24 | private String length; 25 | 26 | @XmlAttribute(name = "type") 27 | public String getType() { 28 | return type; 29 | } 30 | public void setType(String type) { 31 | this.type = type; 32 | } 33 | private String type; 34 | 35 | @XmlValue 36 | public String getValue() { 37 | return value; 38 | } 39 | public void setValue(String value) { 40 | this.value = value; 41 | } 42 | private String value; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/model/BodyDataField.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import javax.xml.bind.annotation.XmlAttribute; 4 | import javax.xml.bind.annotation.XmlValue; 5 | 6 | public class BodyDataField { 7 | 8 | @XmlAttribute(name = "scale") 9 | public String getScale() { 10 | return scale; 11 | } 12 | public void setScale(String scale) { 13 | this.scale = scale; 14 | } 15 | private String scale; 16 | 17 | @XmlAttribute(name = "length") 18 | public String getLength() { 19 | return length; 20 | } 21 | public void setLength(String length) { 22 | this.length = length; 23 | } 24 | private String length; 25 | 26 | @XmlAttribute(name = "type") 27 | public String getType() { 28 | return type; 29 | } 30 | public void setType(String type) { 31 | this.type = type; 32 | } 33 | private String type; 34 | 35 | @XmlValue 36 | public String getValue() { 37 | return value; 38 | } 39 | public void setValue(String value) { 40 | this.value = value; 41 | } 42 | private String value; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/model/ReturnAppHeadData.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import javax.xml.bind.annotation.XmlAttribute; 4 | 5 | public class ReturnAppHeadData { 6 | 7 | @XmlAttribute(name = "name") 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | private String name; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/model/ReturnLocalHeadData.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import javax.xml.bind.annotation.XmlAttribute; 4 | 5 | public class ReturnLocalHeadData { 6 | 7 | @XmlAttribute(name = "name") 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | private String name; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/model/ReturnSysHeadData.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import java.util.List; 4 | 5 | import javax.xml.bind.annotation.XmlAttribute; 6 | import javax.xml.bind.annotation.XmlElement; 7 | import javax.xml.bind.annotation.XmlElementWrapper; 8 | 9 | public class ReturnSysHeadData { 10 | 11 | @XmlAttribute(name = "name") 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | 20 | private String name; 21 | 22 | @XmlElementWrapper(name = "struct") 23 | @XmlElement(name = "data") 24 | public List getSysHeadStructData() { 25 | return sysHeadStructData; 26 | } 27 | 28 | public void setSysHeadStructData(List sysHeadStructData) { 29 | this.sysHeadStructData = sysHeadStructData; 30 | } 31 | 32 | private List sysHeadStructData; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/model/ReturnSysHeadStructData.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import javax.xml.bind.annotation.XmlAttribute; 4 | import javax.xml.bind.annotation.XmlElement; 5 | 6 | public class ReturnSysHeadStructData { 7 | 8 | @XmlAttribute(name = "name") 9 | public String getName() { 10 | return name; 11 | } 12 | 13 | public void setName(String name) { 14 | this.name = name; 15 | } 16 | 17 | private String name; 18 | 19 | @XmlElement(name = "field") 20 | public SysHeadStructDataField getField() { 21 | return field; 22 | } 23 | 24 | public void setField(SysHeadStructDataField field) { 25 | this.field = field; 26 | } 27 | 28 | private SysHeadStructDataField field; 29 | 30 | @XmlElement(name = "array") 31 | public SysHeadStructDataArray getSysHeadStructDataArray() { 32 | return sysHeadStructDataArray; 33 | } 34 | 35 | public void setSysHeadStructDataArray(SysHeadStructDataArray sysHeadStructDataArray) { 36 | this.sysHeadStructDataArray = sysHeadStructDataArray; 37 | } 38 | 39 | private SysHeadStructDataArray sysHeadStructDataArray; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/model/ReturnXMLService.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import java.util.List; 4 | 5 | import javax.xml.bind.annotation.XmlElement; 6 | import javax.xml.bind.annotation.XmlElementWrapper; 7 | import javax.xml.bind.annotation.XmlRootElement; 8 | 9 | @XmlRootElement(name = "service") 10 | public class ReturnXMLService { 11 | 12 | @XmlElementWrapper(name = "sys-header") 13 | @XmlElement(name = "data") 14 | public List getRespSysHeadData() { 15 | return respSysHeadData; 16 | } 17 | 18 | public void setRespSysHeadData(List respSysHeadData) { 19 | this.respSysHeadData = respSysHeadData; 20 | } 21 | 22 | private List respSysHeadData; 23 | 24 | @XmlElement(name = "app-header") 25 | public ReturnAppHeadData getRespAppHeadData() { 26 | return respAppHeadData; 27 | } 28 | 29 | public void setRespAppHeadData(ReturnAppHeadData respAppHeadData) { 30 | this.respAppHeadData = respAppHeadData; 31 | } 32 | 33 | private ReturnAppHeadData respAppHeadData; 34 | 35 | @XmlElement(name = "local-header") 36 | public ReturnLocalHeadData getRespLocalHeadData() { 37 | return respLocalHeadData; 38 | } 39 | 40 | public void setRespLocalHeadData(ReturnLocalHeadData respLocalHeadData) { 41 | this.respLocalHeadData = respLocalHeadData; 42 | } 43 | 44 | private ReturnLocalHeadData respLocalHeadData; 45 | 46 | @XmlElementWrapper(name = "body") 47 | @XmlElement(name = "data") 48 | public List getBodyData() { 49 | return bodyData; 50 | } 51 | 52 | public void setBodyData(List bodyData) { 53 | this.bodyData = bodyData; 54 | } 55 | 56 | private List bodyData; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/model/SubOrder.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | public class SubOrder { 4 | 5 | private String subOrderType; 6 | private String subOrderAmount; 7 | public String getSubOrderType() { 8 | return subOrderType; 9 | } 10 | public void setSubOrderType(String subOrderType) { 11 | this.subOrderType = subOrderType; 12 | } 13 | public String getSubOrderAmount() { 14 | return subOrderAmount; 15 | } 16 | public void setSubOrderAmount(String subOrderAmount) { 17 | this.subOrderAmount = subOrderAmount; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/model/SysHeadStructDataArray.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import java.util.List; 4 | 5 | import javax.xml.bind.annotation.XmlElement; 6 | import javax.xml.bind.annotation.XmlElementWrapper; 7 | 8 | public class SysHeadStructDataArray { 9 | 10 | @XmlElementWrapper(name = "struct") 11 | @XmlElement(name = "data") 12 | public List getSysHeadStructDataArrayData() { 13 | return sysHeadStructDataArrayData; 14 | } 15 | 16 | public void setSysHeadStructDataArrayData(List sysHeadStructDataArrayData) { 17 | this.sysHeadStructDataArrayData = sysHeadStructDataArrayData; 18 | } 19 | 20 | private List sysHeadStructDataArrayData; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/model/SysHeadStructDataArrayData.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import java.util.List; 4 | 5 | import javax.xml.bind.annotation.XmlAttribute; 6 | import javax.xml.bind.annotation.XmlElement; 7 | 8 | public class SysHeadStructDataArrayData { 9 | 10 | @XmlAttribute(name = "name") 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | private String name; 20 | 21 | @XmlElement(name = "field") 22 | public List getSysHeadStructDataArrayDataField() { 23 | return sysHeadStructDataArrayDataField; 24 | } 25 | 26 | public void setSysHeadStructDataArrayDataField( 27 | List sysHeadStructDataArrayDataField) { 28 | this.sysHeadStructDataArrayDataField = sysHeadStructDataArrayDataField; 29 | } 30 | 31 | private List sysHeadStructDataArrayDataField; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/model/SysHeadStructDataArrayDataField.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import javax.xml.bind.annotation.XmlAttribute; 4 | import javax.xml.bind.annotation.XmlValue; 5 | 6 | public class SysHeadStructDataArrayDataField { 7 | 8 | @XmlAttribute(name = "scale") 9 | public String getScale() { 10 | return scale; 11 | } 12 | public void setScale(String scale) { 13 | this.scale = scale; 14 | } 15 | private String scale; 16 | 17 | @XmlAttribute(name = "length") 18 | public String getLength() { 19 | return length; 20 | } 21 | public void setLength(String length) { 22 | this.length = length; 23 | } 24 | private String length; 25 | 26 | @XmlAttribute(name = "type") 27 | public String getType() { 28 | return type; 29 | } 30 | public void setType(String type) { 31 | this.type = type; 32 | } 33 | private String type; 34 | 35 | @XmlValue 36 | public String getValue() { 37 | return value; 38 | } 39 | public void setValue(String value) { 40 | this.value = value; 41 | } 42 | private String value; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/model/SysHeadStructDataField.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import javax.xml.bind.annotation.XmlAttribute; 4 | import javax.xml.bind.annotation.XmlValue; 5 | 6 | public class SysHeadStructDataField { 7 | 8 | @XmlAttribute(name = "scale") 9 | public String getScale() { 10 | return scale; 11 | } 12 | public void setScale(String scale) { 13 | this.scale = scale; 14 | } 15 | private String scale; 16 | 17 | @XmlAttribute(name = "length") 18 | public String getLength() { 19 | return length; 20 | } 21 | public void setLength(String length) { 22 | this.length = length; 23 | } 24 | private String length; 25 | 26 | @XmlAttribute(name = "type") 27 | public String getType() { 28 | return type; 29 | } 30 | public void setType(String type) { 31 | this.type = type; 32 | } 33 | private String type; 34 | 35 | @XmlValue 36 | public String getValue() { 37 | return value; 38 | } 39 | public void setValue(String value) { 40 | this.value = value; 41 | } 42 | private String value; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/model/Traveler.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | public class Traveler { 4 | 5 | private String travelerName; 6 | private String travelerDocumentType; 7 | private String travelerDocumentId; 8 | private String travelerPhone; 9 | public String getTravelerName() { 10 | return travelerName; 11 | } 12 | public void setTravelerName(String travelerName) { 13 | this.travelerName = travelerName; 14 | } 15 | public String getTravelerDocumentType() { 16 | return travelerDocumentType; 17 | } 18 | public void setTravelerDocumentType(String travelerDocumentType) { 19 | this.travelerDocumentType = travelerDocumentType; 20 | } 21 | public String getTravelerDocumentId() { 22 | return travelerDocumentId; 23 | } 24 | public void setTravelerDocumentId(String travelerDocumentId) { 25 | this.travelerDocumentId = travelerDocumentId; 26 | } 27 | public String getTravelerPhone() { 28 | return travelerPhone; 29 | } 30 | public void setTravelerPhone(String travelerPhone) { 31 | this.travelerPhone = travelerPhone; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/pojo/AppCardInfo.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | public class AppCardInfo { 4 | /** 5 | * cardNo 卡号 6 | */ 7 | private String cardNo; 8 | 9 | private String checkOption; 10 | 11 | private String track2; 12 | 13 | private String ccy; 14 | 15 | private String channel; 16 | 17 | private String cupDate; 18 | 19 | private String cupAreaCode; 20 | 21 | private String merchNo; 22 | 23 | private Double tranAmt; 24 | 25 | public String getRetCode() { 26 | return retCode; 27 | } 28 | 29 | public void setRetCode(String retCode) { 30 | this.retCode = retCode; 31 | } 32 | 33 | private String addtnlDataPrivate; 34 | 35 | private String reserved; 36 | 37 | private String integrateOption; 38 | 39 | private String retMsg; 40 | 41 | private String retCode; 42 | 43 | public String getCardNo() { 44 | return cardNo; 45 | } 46 | 47 | public void setCardNo(String cardNo) { 48 | this.cardNo = cardNo; 49 | } 50 | 51 | public String getCheckOption() { 52 | return checkOption; 53 | } 54 | 55 | public void setCheckOption(String checkOption) { 56 | this.checkOption = checkOption; 57 | } 58 | 59 | public String getTrack2() { 60 | return track2; 61 | } 62 | 63 | public void setTrack2(String track2) { 64 | this.track2 = track2; 65 | } 66 | 67 | public String getCcy() { 68 | return ccy; 69 | } 70 | 71 | public void setCcy(String ccy) { 72 | this.ccy = ccy; 73 | } 74 | 75 | public String getChannel() { 76 | return channel; 77 | } 78 | 79 | public void setChannel(String channel) { 80 | this.channel = channel; 81 | } 82 | 83 | public String getCupDate() { 84 | return cupDate; 85 | } 86 | 87 | public void setCupDate(String cupDate) { 88 | this.cupDate = cupDate; 89 | } 90 | 91 | public String getCupAreaCode() { 92 | return cupAreaCode; 93 | } 94 | 95 | public void setCupAreaCode(String cupAreaCode) { 96 | this.cupAreaCode = cupAreaCode; 97 | } 98 | 99 | public String getMerchNo() { 100 | return merchNo; 101 | } 102 | 103 | public void setMerchNo(String merchNo) { 104 | this.merchNo = merchNo; 105 | } 106 | 107 | public String getAddtnlDataPrivate() { 108 | return addtnlDataPrivate; 109 | } 110 | 111 | public void setAddtnlDataPrivate(String addtnlDataPrivate) { 112 | this.addtnlDataPrivate = addtnlDataPrivate; 113 | } 114 | 115 | public String getReserved() { 116 | return reserved; 117 | } 118 | 119 | public void setReserved(String reserved) { 120 | this.reserved = reserved; 121 | } 122 | 123 | public String getIntegrateOption() { 124 | return integrateOption; 125 | } 126 | 127 | public void setIntegrateOption(String integrateOption) { 128 | this.integrateOption = integrateOption; 129 | } 130 | 131 | public String getRetMsg() { 132 | return retMsg; 133 | } 134 | 135 | public void setRetMsg(String retMsg) { 136 | this.retMsg = retMsg; 137 | } 138 | 139 | public Double getTranAmt() { 140 | return tranAmt; 141 | } 142 | 143 | public void setTranAmt(Double tranAmt) { 144 | this.tranAmt = tranAmt; 145 | } 146 | 147 | @Override 148 | public String toString() { 149 | return "AppCardInfo{" + 150 | "cardNo='" + cardNo + '\'' + 151 | ", checkOption='" + checkOption + '\'' + 152 | ", track2='" + track2 + '\'' + 153 | ", ccy='" + ccy + '\'' + 154 | ", channel='" + channel + '\'' + 155 | ", cupDate='" + cupDate + '\'' + 156 | ", cupAreaCode='" + cupAreaCode + '\'' + 157 | ", merchNo='" + merchNo + '\'' + 158 | ", tranAmt='" + tranAmt + '\'' + 159 | ", addtnlDataPrivate='" + addtnlDataPrivate + '\'' + 160 | ", reserved='" + reserved + '\'' + 161 | ", integrateOption='" + integrateOption + '\'' + 162 | ", retMsg='" + retMsg + '\'' + 163 | ", retCode='" + retCode + '\'' + 164 | '}'; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/main/java/pojo/MessageToRedis.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import utils.DataType; 4 | 5 | public class MessageToRedis { 6 | 7 | private String key; 8 | 9 | private String values; 10 | 11 | private DataType dataType; 12 | 13 | 14 | public String getKey() { 15 | return key; 16 | } 17 | 18 | public void setKey(String key) { 19 | this.key = key; 20 | } 21 | 22 | public String getValues() { 23 | return values; 24 | } 25 | 26 | public void setValues(String values) { 27 | this.values = values; 28 | } 29 | 30 | public DataType getDataType() { 31 | return dataType; 32 | } 33 | 34 | public void setDataType(DataType dataType) { 35 | this.dataType = dataType; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/utils/DataType.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.Serializable; 4 | 5 | public enum DataType implements Serializable{ 6 | 7 | STRING, 8 | SET 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/utils/JaxbUtil.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import java.io.StringReader; 6 | import java.io.StringWriter; 7 | import java.util.Collection; 8 | 9 | import javax.xml.bind.JAXBContext; 10 | import javax.xml.bind.JAXBElement; 11 | import javax.xml.bind.JAXBException; 12 | import javax.xml.bind.Marshaller; 13 | import javax.xml.bind.Unmarshaller; 14 | import javax.xml.bind.annotation.XmlAnyElement; 15 | import javax.xml.namespace.QName; 16 | 17 | public class JaxbUtil { 18 | // 多线程安全的Context. 19 | private JAXBContext jaxbContext; 20 | 21 | /** 22 | * @param types 23 | * 所有需要序列化的Root对象的类型. 24 | */ 25 | public JaxbUtil(Class... types) { 26 | try { 27 | jaxbContext = JAXBContext.newInstance(types); 28 | } catch (JAXBException e) { 29 | throw new RuntimeException(e); 30 | } 31 | } 32 | 33 | /** 34 | * Java Object->Xml. 35 | */ 36 | public String toXml(Object root, String encoding) { 37 | try { 38 | StringWriter writer = new StringWriter(); 39 | createMarshaller(encoding).marshal(root, writer); 40 | return writer.toString(); 41 | } catch (JAXBException e) { 42 | throw new RuntimeException(e); 43 | } 44 | } 45 | 46 | /** 47 | * Java Object->Xml, 特别支持对Root Element是Collection的情形. 48 | */ 49 | @SuppressWarnings("unchecked") 50 | public String toXml(Collection root, String rootName, String encoding) { 51 | try { 52 | CollectionWrapper wrapper = new CollectionWrapper(); 53 | wrapper.collection = root; 54 | 55 | JAXBElement wrapperElement = new JAXBElement(new QName(rootName), 56 | CollectionWrapper.class, wrapper); 57 | 58 | StringWriter writer = new StringWriter(); 59 | createMarshaller(encoding).marshal(wrapperElement, writer); 60 | 61 | return writer.toString(); 62 | } catch (JAXBException e) { 63 | throw new RuntimeException(e); 64 | } 65 | } 66 | 67 | /** 68 | * Xml->Java Object. 69 | */ 70 | @SuppressWarnings("unchecked") 71 | public T fromXml(String xml) { 72 | try { 73 | StringReader reader = new StringReader(xml); 74 | return (T) createUnmarshaller().unmarshal(reader); 75 | } catch (JAXBException e) { 76 | throw new RuntimeException(e); 77 | } 78 | } 79 | 80 | /** 81 | * Xml->Java Object, 支持大小写敏感或不敏感. 82 | */ 83 | @SuppressWarnings("unchecked") 84 | public T fromXml(String xml, boolean caseSensitive) { 85 | try { 86 | String fromXml = xml; 87 | if (!caseSensitive) 88 | fromXml = xml.toLowerCase(); 89 | StringReader reader = new StringReader(fromXml); 90 | return (T) createUnmarshaller().unmarshal(reader); 91 | } catch (JAXBException e) { 92 | throw new RuntimeException(e); 93 | } 94 | } 95 | 96 | /** 97 | * 创建Marshaller, 设定encoding(可为Null). 98 | */ 99 | public Marshaller createMarshaller(String encoding) { 100 | try { 101 | Marshaller marshaller = jaxbContext.createMarshaller(); 102 | 103 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 104 | 105 | if (StringUtils.isNotBlank(encoding)) { 106 | marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); 107 | } 108 | return marshaller; 109 | } catch (JAXBException e) { 110 | throw new RuntimeException(e); 111 | } 112 | } 113 | 114 | /** 115 | * 创建UnMarshaller. 116 | */ 117 | public Unmarshaller createUnmarshaller() { 118 | try { 119 | return jaxbContext.createUnmarshaller(); 120 | } catch (JAXBException e) { 121 | throw new RuntimeException(e); 122 | } 123 | } 124 | 125 | /** 126 | * 封装Root Element 是 Collection的情况. 127 | */ 128 | public static class CollectionWrapper { 129 | @SuppressWarnings("unchecked") 130 | @XmlAnyElement 131 | protected Collection collection; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/window/LogRuleBlot.java: -------------------------------------------------------------------------------- 1 | package window; 2 | 3 | import org.apache.storm.task.OutputCollector; 4 | import org.apache.storm.task.TopologyContext; 5 | import org.apache.storm.topology.OutputFieldsDeclarer; 6 | import org.apache.storm.topology.base.BaseRichBolt; 7 | import org.apache.storm.tuple.Tuple; 8 | import org.drools.KnowledgeBase; 9 | import org.drools.KnowledgeBaseFactory; 10 | import org.drools.builder.KnowledgeBuilder; 11 | import org.drools.builder.KnowledgeBuilderFactory; 12 | import org.drools.builder.ResourceType; 13 | import org.drools.io.ResourceFactory; 14 | import org.drools.runtime.StatelessKnowledgeSession; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | import pojo.AppCardInfo; 18 | 19 | import java.io.File; 20 | import java.io.FileInputStream; 21 | import java.io.FileNotFoundException; 22 | import java.util.Map; 23 | 24 | public class LogRuleBlot extends BaseRichBolt { 25 | private static final long serialVersionUID = 1258L; 26 | Logger logger= LoggerFactory.getLogger(LogRuleBlot.class); 27 | private StatelessKnowledgeSession ksession; 28 | private String driFile; 29 | private OutputCollector collector; 30 | 31 | public LogRuleBlot(String driFile){ 32 | this.driFile=driFile; 33 | } 34 | 35 | public void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector) { 36 | this.collector=outputCollector; 37 | KnowledgeBuilder kbuilder= KnowledgeBuilderFactory.newKnowledgeBuilder(); 38 | try { 39 | kbuilder.add(ResourceFactory.newInputStreamResource(new FileInputStream(new File(driFile))), ResourceType.DRL); 40 | } catch (FileNotFoundException e) { 41 | logger.info(e.getMessage()); 42 | } 43 | KnowledgeBase kbase= KnowledgeBaseFactory.newKnowledgeBase(); 44 | kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); 45 | ksession=kbase.newStatelessKnowledgeSession(); 46 | 47 | } 48 | 49 | public void execute(Tuple tuple) { 50 | AppCardInfo appCardInfo=(AppCardInfo)tuple.getValueByField("message"); 51 | 52 | } 53 | 54 | public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) { 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/window/RedisStoreBlot.java: -------------------------------------------------------------------------------- 1 | package window; 2 | 3 | 4 | import org.apache.storm.task.OutputCollector; 5 | import org.apache.storm.task.TopologyContext; 6 | import org.apache.storm.topology.BasicOutputCollector; 7 | import org.apache.storm.topology.OutputFieldsDeclarer; 8 | import org.apache.storm.topology.base.BaseBasicBolt; 9 | import org.apache.storm.tuple.Tuple; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import pojo.MessageToRedis; 13 | import redis.clients.jedis.Jedis; 14 | import redis.clients.jedis.Pipeline; 15 | 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | public class RedisStoreBlot extends BaseBasicBolt{ 20 | 21 | private static final long serialVersionUID = 1L; 22 | public static final Logger logger= LoggerFactory.getLogger(RedisStoreBlot.class); 23 | public static final String LOG_ENTRY = "str"; 24 | private OutputCollector collector; 25 | 26 | private Jedis jedis; 27 | private Pipeline pipeline; 28 | 29 | public void insertToRedis(List redisRecords) { 30 | for(MessageToRedis message :redisRecords) 31 | { 32 | switch (message.getDataType()) 33 | { 34 | 35 | case STRING: 36 | pipeline.set(message.getKey(),message.getValues()); 37 | break; 38 | case SET: 39 | pipeline.zadd(message.getKey(),Double.parseDouble(message.getValues()),message.getValues()); 40 | break; 41 | default:break; 42 | } 43 | } 44 | pipeline.sync(); 45 | } 46 | 47 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 48 | 49 | } 50 | 51 | public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { 52 | this.collector=collector; 53 | this.jedis=new Jedis("10.200.187.73", 6379); 54 | this.pipeline=this.jedis.pipelined(); 55 | } 56 | 57 | 58 | public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) { 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/window/RuleBlot.java: -------------------------------------------------------------------------------- 1 | package window; 2 | 3 | import org.apache.storm.task.OutputCollector; 4 | import org.apache.storm.task.TopologyContext; 5 | import org.apache.storm.topology.BasicOutputCollector; 6 | import org.apache.storm.topology.OutputFieldsDeclarer; 7 | import org.apache.storm.topology.base.BaseBasicBolt; 8 | import org.apache.storm.tuple.Tuple; 9 | import redis.clients.jedis.JedisPool; 10 | import redis.clients.jedis.JedisPoolConfig; 11 | 12 | import java.util.Map; 13 | import java.util.concurrent.ConcurrentHashMap; 14 | 15 | public class RuleBlot extends BaseBasicBolt { 16 | 17 | OutputCollector collector; 18 | 19 | public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { 20 | this.collector = collector; 21 | JedisPoolConfig config = new JedisPoolConfig(); 22 | // 一个pool最多有多少个状态为idle(空闲的)的jedis实例。 23 | config.setMaxIdle(10); 24 | // 最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException; 25 | config.setMaxWaitMillis(1000 * 3); 26 | } 27 | public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) { 28 | 29 | } 30 | 31 | public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) { 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/window/SlidingWindowBolt.java: -------------------------------------------------------------------------------- 1 | package window; 2 | 3 | import clojure.lang.Obj; 4 | import com.alibaba.fastjson.JSON; 5 | import org.apache.storm.task.OutputCollector; 6 | import org.apache.storm.task.TopologyContext; 7 | import org.apache.storm.topology.OutputFieldsDeclarer; 8 | import org.apache.storm.topology.base.BaseWindowedBolt; 9 | import org.apache.storm.tuple.Fields; 10 | import org.apache.storm.tuple.Tuple; 11 | import org.apache.storm.tuple.Values; 12 | import org.apache.storm.windowing.TupleWindow; 13 | import org.apache.storm.windowing.Window; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | import pojo.AppCardInfo; 17 | import redis.clients.jedis.Jedis; 18 | import redis.clients.jedis.JedisPool; 19 | import redis.clients.jedis.JedisPoolConfig; 20 | 21 | import java.util.Map; 22 | import java.util.concurrent.ConcurrentHashMap; 23 | 24 | public class SlidingWindowBolt extends BaseWindowedBolt { 25 | 26 | 27 | private static final long serialVersionUID = 1L; 28 | private OutputCollector collector; 29 | private ConcurrentHashMap concurrentHashMap; 30 | JedisPool pool; 31 | 32 | public static final Logger logger = LoggerFactory.getLogger(SlidingWindowBolt.class); 33 | 34 | @SuppressWarnings("rawtypes") 35 | public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { 36 | this.collector = collector; 37 | concurrentHashMap=new ConcurrentHashMap(); 38 | JedisPoolConfig config = new JedisPoolConfig(); 39 | // 一个pool最多有多少个状态为idle(空闲的)的jedis实例。 40 | config.setMaxIdle(10); 41 | // 最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException; 42 | config.setMaxWaitMillis(1000 * 3); 43 | this.pool = new JedisPool(config, "10.1.69.11", 6379); 44 | logger.debug("prepare ok"); 45 | } 46 | 47 | 48 | 49 | public void execute(TupleWindow input) { 50 | // TODO Auto-generated method stub 51 | Jedis jedis=pool.getResource(); 52 | int sum=0; 53 | System.out.print("一个窗口内的数据"); 54 | for(Tuple tuple: ((Window) input).get()){ 55 | Double tranAmt=0.0; 56 | String str= tuple.getString(0); 57 | Object appCardInfo= JSON.parseObject(str).get("AppCardInfo"); 58 | AppCardInfo cardInf=JSON.parseObject(String.valueOf(appCardInfo), AppCardInfo.class); 59 | logger.info("cardInf:"+cardInf); 60 | 61 | String cardNo=cardInf.getCardNo(); 62 | 63 | if(jedis.exists(cardNo)){ 64 | String keyValue=jedis.get(cardNo); 65 | jedis.set(cardNo,String.valueOf(Double.valueOf(keyValue)+Double.valueOf(cardInf.getTranAmt()))); 66 | }else { 67 | jedis.set(cardNo,String.valueOf(cardInf.getTranAmt())); 68 | } 69 | 70 | /* if(concurrentHashMap.containsKey(cardInf.getCardNo())){ 71 | Double values=(Double)concurrentHashMap.get(cardInf.getCardNo()); 72 | tranAmt=Double.valueOf(cardInf.getTranAmt())+values; 73 | concurrentHashMap.put(cardInf.getCardNo(),String.valueOf(tranAmt)); 74 | jedis.set(cardInf.getCardNo(),String.valueOf(tranAmt)); 75 | }else { 76 | jedis.set(cardInf.getCardNo(),String.valueOf(cardInf.getTranAmt())); 77 | }*/ 78 | } 79 | System.out.println("======="+sum); 80 | 81 | pool.returnResource(jedis); 82 | collector.emit(new Values(sum)); 83 | } 84 | 85 | 86 | 87 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 88 | // TODO Auto-generated method stub 89 | declarer.declare(new Fields("newMessageBean")); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/window/SlidingWindowTopology.java: -------------------------------------------------------------------------------- 1 | package window; 2 | 3 | import org.apache.storm.Config; 4 | import org.apache.storm.StormSubmitter; 5 | import org.apache.storm.generated.AlreadyAliveException; 6 | import org.apache.storm.generated.AuthorizationException; 7 | import org.apache.storm.generated.InvalidTopologyException; 8 | import org.apache.storm.kafka.*; 9 | import org.apache.storm.kafka.bolt.KafkaBolt; 10 | import org.apache.storm.spout.SchemeAsMultiScheme; 11 | import org.apache.storm.topology.TopologyBuilder; 12 | import org.apache.storm.topology.base.BaseWindowedBolt.Duration; 13 | 14 | import java.util.Arrays; 15 | import java.util.concurrent.TimeUnit; 16 | 17 | public class SlidingWindowTopology { 18 | 19 | public static void main(String []args){ 20 | TopologyBuilder builder = new TopologyBuilder(); 21 | 22 | String zks = "10.1.69.11:2181,10.1.69.12:2181,10.1.69.13:2181"; 23 | String topic = "stormKafka"; 24 | String zkRoot = "/storm"; 25 | String id = "stormKafka"; 26 | BrokerHosts brokerHosts = new ZkHosts(zks); 27 | SpoutConfig spoutConf = new SpoutConfig(brokerHosts, topic, zkRoot, id); 28 | spoutConf.scheme = new SchemeAsMultiScheme(new StringScheme()); 29 | 30 | spoutConf.zkServers = Arrays.asList(new String[] { "10.1.69.11", "10.1.69.12", "10.1.69.13"}); 31 | spoutConf.zkPort = 2181; 32 | 33 | //数据从Kafka读取 34 | builder.setSpout("spout", new KafkaSpout(spoutConf), 4); 35 | //定义滑动时间窗口为10 MINUTES 36 | builder.setBolt("slidingwindowbolt", 37 | new SlidingWindowBolt().withWindow(new Duration(10, TimeUnit.SECONDS), new Duration(10, TimeUnit.SECONDS)), 38 | 1).shuffleGrouping("spout"); 39 | // builder.setBolt("kafkabolt", new KafkaBolt()).shuffleGrouping("slidingwindowbolt"); 40 | 41 | Config conf = new Config(); 42 | conf.setDebug(true); 43 | conf.setNumWorkers(1); 44 | 45 | try { 46 | StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology()); 47 | } catch (AlreadyAliveException e) { 48 | e.printStackTrace(); 49 | } catch (InvalidTopologyException e) { 50 | e.printStackTrace(); 51 | } catch (AuthorizationException e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.kafka.bootstrap-servers=10.1.69.11:6667 2 | spring.kafka.consumer.group-id=myGroup 3 | kafka.topic.basictopic=testTopic 4 | spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer 5 | spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer 6 | spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer 7 | spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer -------------------------------------------------------------------------------- /src/main/resources/cardFile.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | SVR_CARD 8 | 9 | 10 | ONLINE 11 | 12 | 13 | UC 14 | 15 | 16 | 027001 17 | 18 | 19 | EC0001 20 | 21 | 22 | 20210917 23 | 24 | 25 | 102648 26 | 27 | 28 | 127.0.0.1 29 | 30 | 31 | CHINESE 32 | 33 | 34 | ECI2021091700071683 35 | 36 | 37 | M 38 | 39 | 40 | cups.gaps.zpk 41 | 42 | 43 | RB 44 | 45 | 46 | 1200 47 | 48 | 49 | 6077 50 | 51 | 52 | 53 | 54 | 55 | 56 | 6236430910100000052 57 | 58 | 59 | 00110 60 | 61 | 62 | 30122200000000661F 63 | 64 | 65 | CNY 66 | 67 | 68 | 11 69 | 70 | 71 | 20211121 72 | 73 | 74 | 92010000 75 | 76 | 77 | 123456789012345 78 | 79 | 80 | ASAO00215 81 | 82 | 83 | 000006000600000000004012000 84 | 85 | 86 | 1000 87 | 88 | 1000 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/main/resources/cardInfo.drl: -------------------------------------------------------------------------------- 1 | import pojo.AppCardInfo 2 | 3 | rule "Hello World" 4 | when 5 | //LHS块 6 | //在working Memory中,AppCardInfo对象,如果刷卡金额大于1000就进行预警 7 | a : AppCardInfo(tranAmt>1000) 8 | then 9 | 10 | 11 | 12 | end -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=INFO, stdout 2 | log4j.rootLogger=info, stdout 3 | 4 | ### stdout ### 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p - %m%n 9 | 10 | ### set package ### 11 | log4j.logger.org.springframework=info 12 | log4j.logger.org.apache.catalina=info 13 | log4j.logger.org.apache.commons.digester.Digester=info 14 | log4j.logger.org.apache.catalina.startup.TldConfig=info 15 | log4j.logger.chb.test=debug -------------------------------------------------------------------------------- /src/test/java/StringTest.java: -------------------------------------------------------------------------------- 1 | import com.alibaba.fastjson.JSON; 2 | import pojo.AppCardInfo; 3 | 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | public class StringTest { 7 | 8 | public static void main(String []args){ 9 | 10 | String str="{\"AppInfoEntity\":{\"addtnlDataPrivate\":\"ASAO00215\",\"cardNo\":\"6236430910100000052\",\"ccy\":\"CNY\",\"channel\":\"11\",\"checkOption\":\"00110\",\"cupAreaCode\":\"92010000\",\"cupDate\":\"20211121\",\"integrateOption\":\"1000\",\"merchNo\":\"123456789012345\",\"reserved\":\"000006000600000000004012000\",\"retCode\":\"000000\",\"retMsg\":\"\",\"track2\":\"30122200000000661F\"},\"sysHeader\":{\"sysHeaderServiceCode\":\"SVR_CARD\",\"seqNo\":\"ECI2021091700071683\"}}"; 11 | int i=str.indexOf("组包报文"); 12 | Object appCardInfo= JSON.parseObject(str).get("AppInfoEntity"); 13 | AppCardInfo cardInf=JSON.parseObject(String.valueOf(appCardInfo), AppCardInfo.class); 14 | System.out.println( cardInf); 15 | 16 | ConcurrentHashMap concurrentHashMap=new ConcurrentHashMap(); 17 | concurrentHashMap.put("ksy","100"); 18 | 19 | System.out.println(concurrentHashMap.get("ksy")); 20 | 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/drools/DroolsTester.java: -------------------------------------------------------------------------------- 1 | package drools; 2 | import org.drools.KnowledgeBase; 3 | import org.drools.KnowledgeBaseFactory; 4 | import org.drools.builder.*; 5 | import org.drools.io.ResourceFactory; 6 | import org.drools.logger.KnowledgeRuntimeLogger; 7 | import org.drools.logger.KnowledgeRuntimeLoggerFactory; 8 | import org.drools.runtime.StatefulKnowledgeSession; 9 | import org.drools.runtime.StatelessKnowledgeSession; 10 | 11 | public class DroolsTester { 12 | 13 | public static void main(String[] args) throws Exception { 14 | try { 15 | 16 | long start=System.currentTimeMillis(); 17 | // load up the knowledge base 18 | KnowledgeBase kbase = readKnowledgeBase(); 19 | StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();//创建会话 20 | // go ! 21 | Message message = new Message(); 22 | message.setMessage("GoodBye"); 23 | message.setStatus(Message.GOODBYE); 24 | ksession.execute(message); 25 | long end=System.currentTimeMillis(); 26 | 27 | System.out.println("end-start:"+String.valueOf(end-start) +" \t message"+message); 28 | } catch (Throwable t) { 29 | t.printStackTrace(); 30 | } 31 | } 32 | 33 | private static KnowledgeBase readKnowledgeBase() throws Exception { 34 | KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();//创建规则构建器 35 | kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"), ResourceType.DRL);//加载规则文件,并增加到构建器 36 | KnowledgeBuilderErrors errors = kbuilder.getErrors(); 37 | if (errors.size() > 0) {//编译规则过程中发现规则是否有错误 38 | for (KnowledgeBuilderError error: errors) {System.out.println("规则中存在错误,错误消息如下:"); 39 | System.err.println(error); 40 | } 41 | throw new IllegalArgumentException("Could not parse knowledge."); 42 | } 43 | KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();//创建规则构建库 44 | kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());//构建器加载的资源文件包放入构建库 45 | return kbase; 46 | } 47 | 48 | public static class Message { 49 | 50 | public static final int HELLO = 0; 51 | public static final int GOODBYE = 1; 52 | 53 | private String message; 54 | 55 | private int status; 56 | 57 | public String getMessage() { 58 | return this.message; 59 | } 60 | 61 | public void setMessage(String message) { 62 | this.message = message; 63 | } 64 | 65 | public int getStatus() { 66 | return this.status; 67 | } 68 | 69 | public void setStatus(int status) { 70 | this.status = status; 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | return "Message{" + 76 | "message='" + message + '\'' + 77 | ", status=" + status + 78 | '}'; 79 | } 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /src/test/java/drools/User.java: -------------------------------------------------------------------------------- 1 | package drools; 2 | 3 | public class User { 4 | 5 | private int money; // 手中的钱 6 | private int kp; // 空瓶数 7 | private int totals; // 喝掉的瓶数 8 | 9 | public int getMoney() { 10 | return money; 11 | } 12 | 13 | public void setMoney(int money) { 14 | this.money = money; 15 | } 16 | 17 | public int getKp() { 18 | return kp; 19 | } 20 | 21 | public void setKp(int kp) { 22 | this.kp = kp; 23 | } 24 | 25 | public int getTotals() { 26 | return totals; 27 | } 28 | 29 | public void setTotals(int totals) { 30 | this.totals = totals; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/trident/StromTrident.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShilongBoy/SpringBootKafka/be19d2f4cb14c6b6d384eb69950833e61f1bbf94/src/test/java/trident/StromTrident.java -------------------------------------------------------------------------------- /src/test/resources/Sample.drl: -------------------------------------------------------------------------------- 1 | import drools.DroolsTester.Message; 2 | 3 | rule "Hello World" 4 | when 5 | //LHS块 6 | //在working Memory中,如果存在一个Message对象满足他的status属性等于Message.HELLO条件, 7 | //就把满足条件的Message实例用变量m表示,他的message属性用myMessage表示,以便在RHS中使用。 8 | m : Message( status == Message.HELLO, myMessage : message ) 9 | then 10 | //RHS块 11 | //在LHS中满足条件就运行RHS块。用到了LHS中的变量m,myMessage 12 | System.out.println( myMessage ); 13 | m.setMessage( "Goodbye cruel world" ); 14 | m.setStatus( Message.GOODBYE ); 15 | update( m );//表示把此Message实例在 working memory中更新.这便会触发名称为"GoodBye"的rule, 16 | end 17 | 18 | rule "GoodBye" 19 | when 20 | m:Message( status == Message.GOODBYE, myMessage : message ) 21 | then 22 | System.out.println( myMessage ); 23 | m.setMessage("this is message from drool"); 24 | end --------------------------------------------------------------------------------