updateBuilderFromAttribute(flowFile, "contentEncoding", builder::contentEncoding); updateBuilderFromAttribute(flowFile, "deliveryMode", mode -> builder.deliveryMode(Integer.parseInt(mode))); updateBuilderFromAttribute(flowFile, "priority", pri -> builder.priority(Integer.parseInt(pri))); updateBuilderFromAttribute(flowFile, "correlationId", builder::correlationId); updateBuilderFromAttribute(flowFile, "replyTo", builder::replyTo);
/** * See api/Job.java for complete description * @param jobId String for job ID * @param taskId String for task ID * @throws Exception when failing to send retry. */ public void sendRetry(String jobId, String taskId) throws Exception { openConnections(); ArrayList approvedAdapters = new ArrayList<String>(); LGPayload cmdPayload = new LGPayload(jobId); JSONObject jobConfig = new JSONObject(); JSONArray tasks = new JSONArray(); // So in the future we can support a list of taskIds if (!taskId.equals("")) { tasks.put(taskId); } jobConfig.put("tasks", tasks); cmdPayload.setJobConfig(jobConfig); LGCommand cmd = new LGCommand(LGCommand.COMMAND_TYPE_RETRY_FAILED_TASKS, jobId, 100, 255, approvedAdapters, cmdPayload); channel.basicPublish( "" //exchange , LGConstants.LEMONGRENADE_COORDINATORCMD //routing key , new AMQP.BasicProperties.Builder().priority(LGConstants.QUEUE_PRIORITY_COMMAND).build() , cmd.toByteArray()); }
public static AMQP.BasicProperties fromJson( JsonObject json ) { if ( json == null ) { return new AMQP.BasicProperties(); } return new AMQP.BasicProperties.Builder() .contentType(json.getString("contentType")) .contentEncoding(json.getString("contentEncoding")) .headers(asMap(json.getJsonObject("headers"))) .deliveryMode(json.getInteger("deliveryMode")) .priority(json.getInteger("priority")) .correlationId(json.getString("correlationId")) .replyTo(json.getString("replyTo")) .expiration(json.getString("expiration")) .messageId(json.getString("messageId")) .timestamp(parseDate(json.getString("timestamp"))) .type(json.getString("type")) .userId(json.getString("userId")) .appId(json.getString("appId")) .clusterId(json.getString("clusterId")).build(); }
, new AMQP.BasicProperties.Builder().priority(LGConstants.QUEUE_PRIORITY_NEW_JOB).build() , cmd.toByteArray()); return job;
openConnection(); channel.basicPublish("", LGConstants.LEMONGRENADE_COORDINATOR , new AMQP.BasicProperties.Builder().priority(LGConstants.QUEUE_PRIORITY_NEW_JOB).build() , lgp.toByteArray()); log.info("Sending add to job "+jobId+" payload to " + LGConstants.LEMONGRENADE_COORDINATOR);
openConnection(); channel.basicPublish("", LGConstants.LEMONGRENADE_COORDINATOR , new AMQP.BasicProperties.Builder().priority(LGConstants.QUEUE_PRIORITY_NEW_JOB).build() , lgp.toByteArray()); log.info("Sending incoming Post Action payload to " + LGConstants.LEMONGRENADE_COORDINATOR);
@Override public BasicProperties fromMessageProperties(final MessageProperties source, final String charset) { BasicProperties.Builder target = new BasicProperties.Builder(); target.headers(this.convertHeadersIfNecessary(source.getHeaders())) .timestamp(source.getTimestamp()) .messageId(source.getMessageId()) .userId(source.getUserId()) .appId(source.getAppId()) .clusterId(source.getClusterId()) .type(source.getType()); MessageDeliveryMode deliveryMode = source.getDeliveryMode(); if (deliveryMode != null) { target.deliveryMode(MessageDeliveryMode.toInt(deliveryMode)); } target.expiration(source.getExpiration()) .priority(source.getPriority()) .contentType(source.getContentType()) .contentEncoding(source.getContentEncoding()); String correlationId = source.getCorrelationId(); if (StringUtils.hasText(correlationId)) { target.correlationId(correlationId); } String replyTo = source.getReplyTo(); if (replyTo != null) { target.replyTo(replyTo); } return target.build(); }
@Override public BasicProperties fromMessageProperties(final MessageProperties source, final String charset) { BasicProperties.Builder target = new BasicProperties.Builder(); target.headers(this.convertHeadersIfNecessary(source.getHeaders())) .timestamp(source.getTimestamp()) .messageId(source.getMessageId()) .userId(source.getUserId()) .appId(source.getAppId()) .clusterId(source.getClusterId()) .type(source.getType()); MessageDeliveryMode deliveryMode = source.getDeliveryMode(); if (deliveryMode != null) { target.deliveryMode(MessageDeliveryMode.toInt(deliveryMode)); } target.expiration(source.getExpiration()) .priority(source.getPriority()) .contentType(source.getContentType()) .contentEncoding(source.getContentEncoding()); String correlationId = source.getCorrelationId(); if (StringUtils.hasText(correlationId)) { target.correlationId(correlationId); } String replyTo = source.getReplyTo(); if (replyTo != null) { target.replyTo(replyTo); } return target.build(); }
/** * @param jobId LG job ID to send to * @param approvedAdapters List of approved adapter names * @param seedPayload LGPayload for seeding a new job * */ public void sendAddToJobToCommandController(String jobId, ArrayList<String> approvedAdapters, LGPayload seedPayload) throws Exception { openConnections(); int ttl = 0; if (seedPayload.getJobConfig().has("ttl")) { ttl = seedPayload.getJobConfig().getInt("ttl"); } try { LemonGraph.getGraph(jobId); //verify the job already exists in LemonGraph } catch(Exception e) { throw new Exception("job:"+jobId+" doesn't exist. First perform a job create. Error:"+e.getMessage()); } seedPayload.setJobId(jobId); LGCommand cmd = new LGCommand(LGCommand.COMMAND_TYPE_ADD, jobId, ttl, 255, approvedAdapters, seedPayload); channel.basicPublish("", LGConstants.LEMONGRENADE_COORDINATORCMD , new AMQP.BasicProperties.Builder().priority(LGConstants.QUEUE_PRIORITY_NEW_JOB).build() , cmd.toByteArray()); }
private void sendAMQPMessage(RMQDestination destination, RMQMessage msg, int deliveryMode, int priority, long timeToLive) throws JMSException { if (!destination.amqpWritable()) { this.logger.error("Cannot write to AMQP destination {}", destination); throw new RMQJMSException("Cannot write to AMQP destination", new UnsupportedOperationException("MessageProducer.send to undefined AMQP resource")); } if (msg instanceof RMQBytesMessage || msg instanceof RMQTextMessage) { try { AMQP.BasicProperties.Builder bob = new AMQP.BasicProperties.Builder(); bob.contentType("application/octet-stream"); bob.deliveryMode(RMQMessage.rmqDeliveryMode(deliveryMode)); bob.priority(priority); bob.expiration(rmqExpiration(timeToLive)); bob.headers(msg.toAmqpHeaders()); maybeSetReplyToPropertyToDirectReplyTo(bob, msg); bob = amqpPropertiesCustomiser.apply(bob, msg); byte[] data = msg.toAmqpByteArray(); this.session.getChannel().basicPublish(destination.getAmqpExchangeName(), destination.getAmqpRoutingKey(), bob.build(), data); } catch (IOException x) { throw new RMQJMSException(x); } } else { this.logger.error("Unsupported message type {} for AMQP destination {}", msg.getClass().getName(), destination); throw new RMQJMSException("Unsupported message type for AMQP destination", new UnsupportedOperationException("MessageProducer.send to AMQP resource: Message not Text or Bytes")); } }
@Test public void test() throws KeyManagementException, NoSuchAlgorithmException, URISyntaxException, IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("10.211.55.20"); factory.setPort(5672); factory.setVirtualHost("/"); factory.setUsername("guest"); factory.setPassword("guest"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare("KipcastDirect", "direct", true, /* durable */ true, /* autodelete */ null); /* */ byte[] messageBodyBytes = "Hello, world!".getBytes(); AMQP.BasicProperties.Builder basic = new AMQP.BasicProperties.Builder(); AMQP.BasicProperties minBasic = basic.build(); minBasic = basic.priority(0).deliveryMode(1).build(); channel.basicPublish("KipcastDirect", "KipcastRouting", minBasic, messageBodyBytes); System.out.println(" [x] Sent "); channel.close(); }
public static AMQP.BasicProperties box(Message msg) { AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder(); return builder.messageId(String.valueOf(msg.getMessageId())) .appId(msg.getAppId()) .clusterId(msg.getClusterId()) .contentEncoding(msg.getContentEncoding()) .contentType(msg.getContentType()) .correlationId(msg.getCorrelationId()) .deliveryMode((int) msg.getDeliveryMode()) .expiration(msg.getExpiration()) .headers(msg.getHeaders()) .priority((int) msg.getPriority()) .replyTo(msg.getReplyTo()) .timestamp(new Date(msg.getTimestamp())) .type(msg.getType()) .userId(msg.getUserId()) .build(); }
protected void sendJMSMessage(RMQDestination destination, RMQMessage msg, int deliveryMode, int priority, long timeToLive) throws JMSException { this.session.declareDestinationIfNecessary(destination); try { AMQP.BasicProperties.Builder bob = new AMQP.BasicProperties.Builder(); bob.contentType("application/octet-stream"); bob.deliveryMode(RMQMessage.rmqDeliveryMode(deliveryMode)); bob.priority(priority); bob.expiration(rmqExpiration(timeToLive)); bob.headers(msg.toHeaders()); maybeSetReplyToPropertyToDirectReplyTo(bob, msg); byte[] data = msg.toByteArray(); this.session.getChannel().basicPublish(destination.getAmqpExchangeName(), destination.getAmqpRoutingKey(), bob.build(), data); } catch (IOException x) { throw new RMQJMSException(x); } }
/** * See api/Job.java for complete description * @param jobId LG job ID to send to * @param approvedAdapters List of approved adapter names * @param seedPayload LGPayload to send to Command Controller */ public void sendPostActionCommandController(String jobId, ArrayList<String> approvedAdapters, LGPayload seedPayload) throws Exception { openConnections(); int ttl = 0; if (seedPayload.getJobConfig().has("ttl")) { ttl = seedPayload.getJobConfig().getInt("ttl"); } seedPayload.setJobId(jobId); LGCommand cmd = new LGCommand(LGCommand.COMMAND_TYPE_POST_ACTION, jobId, ttl, 255, approvedAdapters, seedPayload); channel.basicPublish("", LGConstants.LEMONGRENADE_COORDINATORCMD , new AMQP.BasicProperties.Builder().priority(LGConstants.QUEUE_PRIORITY_NEW_JOB).build() , cmd.toByteArray()); }
/** * See api/Job.java for complete description * @param jobId String job ID * @param reason String reason for reset * */ public void sendReset(String jobId, String reason) throws Exception { openConnections(); ArrayList approvedAdapters = new ArrayList<String>(); LGPayload cmdPayload = new LGPayload(jobId); JSONObject jobConfig = new JSONObject(); jobConfig.put(LGConstants.LG_RESET_REASON, reason); cmdPayload.setJobConfig(jobConfig); LGCommand cmd = new LGCommand(LGCommand.COMMAND_TYPE_RESET, jobId, 100, 255, approvedAdapters, cmdPayload); channel.basicPublish("", LGConstants.LEMONGRENADE_COORDINATORCMD , new AMQP.BasicProperties.Builder().priority(LGConstants.QUEUE_PRIORITY_COMMAND).build() , cmd.toByteArray()); }
StringPublisherCallback() { this.props = new BasicProperties.Builder() .contentType("text/plain") .deliveryMode(1) .priority(0) .build(); }
@Inject JsonPublisherCallback(@JsonMapper final ObjectMapper mapper) { this.mapper = mapper; this.props = new BasicProperties.Builder() .contentType("application/json") .deliveryMode(1) .priority(0) .build(); }
/** */ public void sendCancel(String jobId) throws Exception { openConnections(); ArrayList approvedAdapters = new ArrayList<String>(); LGPayload seedPayload = new LGPayload(jobId); LGCommand cmd = new LGCommand(LGCommand.COMMAND_TYPE_STOP, jobId, 100, 255, approvedAdapters, seedPayload); channel.basicPublish("", LGConstants.LEMONGRENADE_COORDINATORCMD , new AMQP.BasicProperties.Builder().priority(LGConstants.QUEUE_PRIORITY_COMMAND).build() , cmd.toByteArray()); }
public BasicProperties toBasicProperties() { BasicProperties.Builder builder = new BasicProperties.Builder(); return builder.appId(appId).clusterId(clusterId).contentEncoding(contentEncoding).contentType(contentType).correlationId(correlationId) .deliveryMode(deliveryMode).expiration(expiration).headers(headers).messageId(messageId).priority(priority).replyTo(replyTo) .timestamp(timestamp).type(type).userId(userId).build(); }