| | |
| | | GetTopicInfoRequest getTopicInfoRequest = new GetTopicInfoRequest(); |
| | | getTopicInfoRequest.setEventTypes(new ArrayList<Long>(){{ |
| | | add(5201154049L); |
| | | add(5201301505L); |
| | | }}); |
| | | String eventSubscriptionView = Artemis.getTopicInfo(getTopicInfoRequest); |
| | | JSONObject jsonObject = JSON.parseObject(eventSubscriptionView); |
| | | String code = jsonObject.getString("code"); |
| | | if("0".equals(code)){ |
| | | JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("detail"); |
| | | List<String> list = new ArrayList<>(); |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | JSONArray eventTypes = jsonArray.getJSONObject(i).getJSONArray("eventTypes"); |
| | | eventTypes.forEach(eventType -> { |
| | | list.add(eventType.toString()); |
| | | }); |
| | | } |
| | | //告警事件类型 |
| | | if(!list.contains("5201154049")){ |
| | | //订阅事件 |
| | | EventSubscriptionByEventTypesRequest eventSubscriptionByEventTypesRequest = new EventSubscriptionByEventTypesRequest(); |
| | | eventSubscriptionByEventTypesRequest.setSubWay(1); |
| | | eventSubscriptionByEventTypesRequest.setEventDest("http://221.182.45.100:1000/dataInterchange/warnMsgAdptInfo/alarmNotice"); |
| | | eventSubscriptionByEventTypesRequest.setEventTypes(new ArrayList<String>(){{ |
| | | add("5201154049"); |
| | | }}); |
| | | String subscription = Artemis.eventSubscriptionByEventTypes(eventSubscriptionByEventTypesRequest); |
| | | jsonObject = JSON.parseObject(subscription); |
| | | code = jsonObject.getString("code"); |
| | | if(!"0".equals(code)){ |
| | | log.error("告警事件订阅失败"); |
| | | }else { |
| | | log.info("告警事件订阅成功"); |
| | | } |
| | | } |
| | | }else{ |
| | | log.error("查询事件订阅信息失败"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json"); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | Artemis.run(); |
| | | } |
| | | } |