List of usage examples for com.rabbitmq.client MessageProperties PERSISTENT_TEXT_PLAIN
BasicProperties PERSISTENT_TEXT_PLAIN
To view the source code for com.rabbitmq.client MessageProperties PERSISTENT_TEXT_PLAIN.
Click Source Link
From source file:info.pancancer.arch3.worker.WorkerRunnable.java
License:Open Source License
/** * This function will execute a workflow, based on the content of the Job object that is passed in. * * @param message/*from w w w . ja v a 2s. com*/ * - The message that will be published on the queue when the worker starts running the job. * @param job * - The job contains information about what workflow to execute, and how. * @return The complete stdout and stderr from the workflow execution will be returned. */ private WorkflowResult launchJob(String message, Job job, String seqwareEngine, String seqwareSettingsFile, String dockerImage) { WorkflowResult workflowResult = null; ExecutorService exService = Executors.newFixedThreadPool(2); WorkflowRunner workflowRunner = new WorkflowRunner(); try { Path pathToINI = writeINIFile(job); resultsChannel.basicPublish(this.resultsQueueName, this.resultsQueueName, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes(StandardCharsets.UTF_8)); resultsChannel.waitForConfirms(); //TODO: Parameterize dockerImage if (dockerImage == null || dockerImage.trim() == null) { dockerImage = "pancancer/seqware_whitestar_pancancer:latest"; } CommandLine cli = new CommandLine("docker"); cli.addArgument("run"); List<String> args = new ArrayList<>( Arrays.asList("--rm", "-h", "master", "-t", "-v", "/var/run/docker.sock:/var/run/docker.sock", "-v", job.getWorkflowPath() + ":/workflow", "-v", pathToINI + ":/ini", "-v", "/datastore:/datastore", "-v", "/home/" + this.userName + "/.gnos:/home/ubuntu/.gnos")); if (seqwareSettingsFile != null) { args.addAll(Arrays.asList("-v", seqwareSettingsFile + ":/home/seqware/.seqware/settings")); } args.addAll(Arrays.asList(dockerImage, "seqware", "bundle", "launch", "--dir", "/workflow", "--ini", "/ini", "--no-metadata", "--engine", seqwareEngine)); String[] argsArray = new String[args.size()]; cli.addArguments(args.toArray(argsArray)); WorkerHeartbeat heartbeat = new WorkerHeartbeat(); heartbeat.setQueueName(this.resultsQueueName); // channels should not be shared between threads https://www.rabbitmq.com/api-guide.html#channel-threads // heartbeat.setReportingChannel(resultsChannel); heartbeat.setSettings(settings); heartbeat.setSecondsDelay( settings.getDouble(Constants.WORKER_HEARTBEAT_RATE, WorkerHeartbeat.DEFAULT_DELAY)); heartbeat.setJobUuid(job.getUuid()); heartbeat.setVmUuid(this.vmUuid); heartbeat.setNetworkID(this.networkAddress); heartbeat.setStatusSource(workflowRunner); long presleep = settings.getLong(Constants.WORKER_PREWORKER_SLEEP, WorkerRunnable.DEFAULT_PRESLEEP); long postsleep = settings.getLong(Constants.WORKER_POSTWORKER_SLEEP, WorkerRunnable.DEFAULT_POSTSLEEP); long presleepMillis = Base.ONE_SECOND_IN_MILLISECONDS * presleep; long postsleepMillis = Base.ONE_SECOND_IN_MILLISECONDS * postsleep; workflowRunner.setCli(cli); workflowRunner.setPreworkDelay(presleepMillis); workflowRunner.setPostworkDelay(postsleepMillis); // Submit both @SuppressWarnings("unused") // We will never actually do submit.get(), because the heartbeat should keep running until it is terminated by // exService.shutdownNow(). Future<?> submit = exService.submit(heartbeat); Future<WorkflowResult> workflowResultFuture = exService.submit(workflowRunner); // make sure both are complete workflowResult = workflowResultFuture.get(); // don't get the heartbeat if the workflow is complete already log.info("Docker execution result: " + workflowResult.getWorkflowStdout()); } catch (SocketException e) { // This comes from trying to get the IP address. log.error(e.getMessage(), e); } catch (IOException e) { // This could be caused by a problem writing the file, or publishing a message to the queue. log.error(e.getMessage(), e); } catch (ExecutionException e) { log.error("Error executing workflow: " + e.getMessage(), e); } catch (InterruptedException e) { log.error("Workflow may have been interrupted: " + e.getMessage(), e); } finally { exService.shutdownNow(); } return workflowResult; }
From source file:info.pancancer.arch3.worker.WorkerRunnable.java
License:Open Source License
/** * Publish a message stating that the job is finished. * * @param message//from w ww . j a v a2s.c om * - The actual message to publish. */ private void finishJob(String message) { log.info("Publishing worker results to results channel " + this.resultsQueueName + ": " + message); try { boolean success = false; do { try { resultsChannel.basicPublish(this.resultsQueueName, this.resultsQueueName, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes(StandardCharsets.UTF_8)); resultsChannel.waitForConfirms(); success = true; } catch (AlreadyClosedException e) { // retry indefinitely if the connection is down log.error("could not send closed message, retrying", e); Thread.sleep(Base.ONE_MINUTE_IN_MILLISECONDS); } } while (!success); } catch (IOException | InterruptedException e) { log.error(e.toString()); } log.info("Finished job report, let's call it a day"); }
From source file:it.polimi.tower4clouds.observers.hdb.manager.Queue.java
License:Apache License
private void internalAddMessage(String message) throws IOException { channel.queueDeclare(queueName, true, false, false, null); channel.basicPublish("", queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes()); logger.debug("Message added:\n{}", message); }
From source file:localdomain.localhost.RabbitMQServer.java
License:Apache License
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from w w w .ja va 2s. c o m*/ String message = request.getParameter("message"); ConnectionFactory factory = new ConnectionFactory(); String uri = System.getProperty("CLOUDAMQP_URL"); factory.setUri(uri); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); boolean durable = true; channel.queueDeclare(QUEUE_NAME, durable, false, false, null); channel.basicPublish("", QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes()); System.out.println(" [x] Sent '" + message + "'"); channel.close(); connection.close(); response.sendRedirect(request.getContextPath() + "/index.jsp"); } catch (Exception e) { request.setAttribute("throwable", e); request.getRequestDispatcher("/index.jsp").forward(request, response); } }
From source file:messaging.Worker.java
License:Apache License
public static void sendMessage(String message) throws java.io.IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(ConfigurationLoader.getInstance().getRabbitmqNodename()); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes()); System.out.println(" [x] Sent '" + message + "'"); channel.close();/*from w w w . jav a 2 s .c om*/ connection.close(); }
From source file:net.duckling.falcon.api.mq.impl.DFMQBasePublisherClient.java
License:Apache License
protected void publishMessage(Object obj, String routingKey) { try {/* w w w . j a va 2 s . c o m*/ if (obj != null) { channel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, DFMessageSerializer.serialize(obj)); } else { LOG.info("The object to send as a message should not be null."); } } catch (IOException e) { LOG.error("IO exception for send message.", e); } }
From source file:nl.uva.sne.drip.commons.utils.DRIPLogHandler.java
License:Apache License
@Override public void publish(LogRecord record) { try (Connection connection = factory.newConnection()) { Channel channel = connection.createChannel(); SecurityContext ctx = SecurityContextHolder.getContext(); Authentication auth = ctx.getAuthentication(); if (auth != null) { User user = (User) auth.getPrincipal(); setOwner(user.getUsername()); }//from w w w .j a v a 2 s . co m DRIPLogRecord dripLog = DRIPLogRecordFactory.create(record); dripLog.setOwner(getOwner()); String jsonInString = mapper.writeValueAsString(dripLog); // channel.basicPublish(qeueName, owner, null, jsonInString.getBytes()); // channel.basicPublish(qeueName, owner, MessageProperties.PERSISTENT_TEXT_PLAIN, jsonInString.getBytes("UTF-8")); String qeueNameUser = qeueName + "_" + getOwner(); channel.queueDeclare(qeueNameUser, true, false, false, null); channel.basicPublish("", qeueNameUser, MessageProperties.PERSISTENT_TEXT_PLAIN, jsonInString.getBytes("UTF-8")); } catch (JsonProcessingException ex) { Logger.getLogger(DRIPLogHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException | TimeoutException ex) { Logger.getLogger(DRIPLogHandler.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.apache.airavata.messaging.core.impl.RabbitMQProducer.java
License:Apache License
public void sendToWorkerQueue(byte[] message, String routingKey) throws Exception { try {// w w w . j a v a 2s . c o m channel.basicPublish("", routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, message); } catch (IOException e) { String msg = "Failed to publish message to exchange: " + exchangeName; log.error(msg, e); throw new Exception(msg, e); } }
From source file:org.apache.airavata.messaging.core.impl.RabbitMQPublisher.java
License:Apache License
public void send(byte[] message, String routingKey) throws Exception { try {/*from w ww.j av a 2s. c o m*/ channel.basicPublish(properties.getExchangeName(), routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, message); } catch (IOException e) { String msg = "Failed to publish message to exchange: " + properties.getExchangeName(); log.error(msg, e); throw new Exception(msg, e); } }
From source file:org.apache.cloudstack.mom.rabbitmq.RabbitMQEventBus.java
License:Apache License
private void publishEventToExchange(Channel channel, String exchangeName, String routingKey, String eventDescription) throws Exception { try {/*from w ww . j a va 2 s .c o m*/ byte[] messageBodyBytes = eventDescription.getBytes(); channel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes); } catch (Exception e) { s_logger.error("Failed to publish event " + routingKey + " on exchange " + exchangeName + " of message broker due to " + e.getMessage()); throw e; } }