@Override Status execute() { Status status = new Status(); // sanity checks first if (time_from == null || time_to == null || time_from < 0L || time_to < time_from) { status.setClientError("Invalid FROM and TO (unit to be in milliseconds)"); return status; } try { // validate request and get list of records List<String> accounts = validateRequestBody(request); // request CDR to flush data for these accounts FlushCDRs flushCDRs = new FlushCDRs(time_from, time_to, accounts); BillRequest billRequest = new BillRequest(time_from, time_to, accounts, request); // extract routing keys from the configuration file RoutingKeys keys = Loader.extractProperties(RoutingKeys.class); // and also forward this request to CoinBill if (Messenger.publish(flushCDRs, keys.getPublishToCDRWithKey()) && Messenger.publish(billRequest, keys.getPublishToCoinBillWithKey())) status.setSuccessful(String.format("GenerateBill request processed for %d - %d", time_from, time_to)); else status.setServerError(String.format("GenerateBill unable to notify CDR and CoinBill for %d - %d due to RabbitMQ", time_from, time_to)); } catch (Exception e) { status.setClientError(e.getMessage()); } return status; }
if (Messenger.broadcast(UDRs)) { message = String.format("Flushed %d UDRs (starting and ending between %s and %s period)", UDRs.size(), new Timestamp(time_from), new Timestamp(time_to)); status.setSuccessful(message);
/** * Manually execute and fire all rules * @return result containing updated facts or null if rules failed */ public List<Object> fireAllRulesNow() throws Exception{ // get state full knowledge session first StatefulKnowledgeSession session = getSharedStatefulKnowledgeSession(); // register global messenger for RESTful container and RabbitMQ Messenger messenger = Messenger.getInstance(); session.setGlobal("messenger", messenger); // fire all rules session.fireAllRules(); // return content of the container return messenger.retrieveRestfulContainer(); }
/** * Used when stream processing facts * @param facts to be processed * @return number of executed rules */ public Integer streamProcessFacts(List<MappedFact> facts) { // preload facts StatefulKnowledgeSession session = loadFacts(facts); try { // set global if possible session.setGlobal("messenger", Messenger.getInstance()); } catch (Exception ignored) {} // execute return session.fireAllRules(); }
/** * ACK the message if it is coming from RabbitMQ, but publish it via an exchange * In case that publishing fails, NACK it and optionally schedule a health check */ private void publishAndIfSuccessfulAck() { if (deliveryTag != null) { boolean published = Messenger.publish(content, INVALID_RECORDS_ROUTING_KEY); if (published) consumer.ackMessage(deliveryTag); else { consumer.nackMessage(deliveryTag); if (healthCheck) TaskExecutor.getInstance().executeNow(new HealthCheck()); } } }
@Override Status execute() { Status status = new Status(); // sanity checks first if (time_from == null || time_to == null || time_from < 0L || time_to < time_from) { status.setClientError("Invalid FROM and TO (unit to be in milliseconds)"); return status; } try { // validate request and get list of records List<String> accounts = validateRequestBody(request); // request CDR to flush data for these accounts FlushCDRs flushCDRs = new FlushCDRs(time_from, time_to, run, accounts); BillRequest billRequest = new BillRequest(time_from, time_to, run, accounts, request); // extract routing keys from the configuration file RoutingKeys keys = Loader.extractProperties(RoutingKeys.class); // and also forward this request to CoinBill if (Messenger.publish(flushCDRs, keys.getPublishToCDRWithKey()) && Messenger.publish(billRequest, keys.getPublishToCoinBillWithKey())) status.setSuccessful(String.format("GenerateBill request processed for %d - %d", time_from, time_to)); else status.setServerError(String.format("GenerateBill unable to notify CDR and CoinBill for %d - %d due to RabbitMQ", time_from, time_to)); } catch (Exception e) { status.setClientError(e.getMessage()); } return status; }
/** * ACK the message if it is coming from RabbitMQ, but publish it via an exchange * In case that publishing fails, NACK it and optionally schedule a health check */ private void publishAndIfSuccessfulAck() { if (deliveryTag != null) { boolean published = Messenger.publish(content, INVALID_RECORDS_ROUTING_KEY); if (published) consumer.ackMessage(deliveryTag); else { consumer.nackMessage(deliveryTag); if (healthCheck) TaskExecutor.getInstance().executeNow(new HealthCheck()); } } }
/** * ACK the message if it is coming from RabbitMQ, but publish it via an exchange * In case that publishing fails, NACK it and optionally schedule a health check */ private void publishAndIfSuccessfulAck() { if (deliveryTag != null) { boolean published = Messenger.publish(content, INVALID_RECORDS_ROUTING_KEY); if (published) consumer.ackMessage(deliveryTag); else { consumer.nackMessage(deliveryTag); if (healthCheck) TaskExecutor.getInstance().executeNow(new HealthCheck()); } } }
@Override Status execute() { Status status = new Status(); try { // replace now reference with the specified date now = DateTime.parse(today).withTimeAtStartOfDay(); } catch (Exception ignored) {} // extract monthly, quarterly, half-yearly and yearly list of resellers from the schedule if (!extractSchedule(schedule)) status.setClientError("Invalid request, nothing to process"); else { // monthly, quarterly, half-yearly and yearly bill requests List<GenerateBillRun> requests = getBillRequests(); if (requests == null) { status.setServerError("Couldn't generate list of Bill Request commands"); } else if (requests.isEmpty()) { status.setSuccessful("Nothing to generate for today"); } else { RoutingKey key = Loader.extractProperties(RoutingKey.class); for (Command command: requests) { if (!Messenger.publish(command, key.getPublishToSelf())) { status.setServerError("Couldn't publish one of generated commands to the RabbitMQ"); return status; } } status.setSuccessful(String.format("Created and published %d Bill Request commands", requests.size())); } } return status; }
if (!Messenger.publish(command, key.getPublishToSelf())) { status.setServerError("Couldn't publish one of generated commands to the RabbitMQ"); return status;
if (!Messenger.publish(command, key.getPublishToSelf())) { status.setServerError("Couldn't publish one of generated commands to the RabbitMQ"); return status;
flushUDRs.setCommand(flushUDRs.getClass().getSimpleName()); Messenger.publish(flushUDRs, Loader.getSettings().getPublisherCredentials().getRoutingKeyPublishUDRCommand());
boolean status = Messenger.publish(content, INVALID_RECORDS_ROUTING_KEY); if (status) consumer.ackMessage(deliveryTag);
boolean status = Messenger.publish(content, INVALID_RECORDS_ROUTING_KEY); if (status) consumer.ackMessage(deliveryTag);
boolean status = Messenger.publish(content, INVALID_RECORDS_ROUTING_KEY); if (status) consumer.ackMessage(deliveryTag);