Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.2 kB
2
Indexable
Never
	public void run(String... args) throws Exception {
		log.info("[QmsImportQueuesApplication::run] BEGIN");
		// recupero api di artemis richiamando service Jolokia
		Map<String, ? extends QueueMetrics> metricsMap = queueMetricsService.getMetricsViaJolokia(null); // il consumer ritorna un'istanza condivisa
		
		boolean hasAppAll = true;	
		
		metricsMap.values().removeIf(qm -> {
			QueueName qn;
			try {
				//Modifica 2022 che permette il recupero delle code topics
				qn = new QueueName(qm.getName());
				log.info("queueName : " + qn);
				//qn = new QueueName(qm.getName(),qm.getAddress());
			} catch (QueueNameSyntaxException e) {
				//	log.error("Queue che non rispetta il nome "+qm.getName(),e);
				return true;
			}
			return !hasAppAll;
		});

		// Create list of importable queues
		List<ImportableQueueDto> allImportableQueues = metricsMap.values()
		.stream()
		.map((QueueMetrics mq) -> ImportableQueueDto.builder()
		.id(mq.getName())
		.address(mq.getAddress())
		.messageCount(mq.getTotalMessageCount())
		.consumerCount(mq.getConsumerCount())
		.threshold(mq.getName().endsWith(QueueName.ERROR_SUFFIX) ? 0 : 1000)
		.monitored(true)
		.selectedRow(true)
		.build()
		)
		.collect(Collectors.toList());
		
		// verifico quantità oggetti lista presa da Jolokia		
		log.info("allImportableQueues size : " + allImportableQueues.size());
		
		// ciclo ogni oggetto in allImportableQueues per creare un dto di Queue 
		// e passarlo a queueService per ensureAppAssett e salvarli tutti 
		for (ImportableQueueDto importableQueueDto : allImportableQueues) {
			log.info("object queue : " + importableQueueDto.toString());
			Queue queueModel = new Queue();
			queueModel.setId(importableQueueDto.getId());
			queueModel.setAddress(importableQueueDto.getAddress());
			queueModel.setMonitored(importableQueueDto.isMonitored()); 
			queueModel.setThreshold(importableQueueDto.getThreshold());
			log.info("queue dto : " + queueModel.toString());
			queueService.ensureApplicationAsset(queueModel);
			queueService.save(queueModel);
		}

		log.info("[QmsImportQueuesApplication::run] END");
		System.exit(0);
	}
Leave a Comment