Correlate message but with unique id - cannot be found

@Niall I am trying to correlate a message but I have a lot of messages and every message is connected to the login user.
So the user can run only a particular message but not all messages that are waiting to be executed.
So my message name looks like that: myHome-${execution.processBusinessKey}

image

the code that I am using in Java is:

	    	runtimeService.createMessageCorrelation("myHome-" + home.get().getBusinessKey())
					.processInstanceBusinessKey(home.get().getBusinessKey())
					.setVariable(CustomerInteractionProcessConstants.Variables.CHOSEN_HOME,
							choice.getHome())
					.setVariable(CustomerInteractionProcessConstants.Variables.CHOSEN_HOTEL,
							choice.getHotel())
					.correlate();

And the error that I get is:

org.camunda.bpm.engine.MismatchingMessageCorrelationException: Cannot correlate message ‘myHome-20210407378941000000001’: No process definition matches the parameters

Hi @Niall I found solution that worked for me. I didnt understand why the normal solution above did not work… hope that this example will help other people with similar issue.

EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().eventName("myHome-"+ order.get().getId()).eventType("message").singleResult();
			if (eventSubscription == null) {
				String errorMessage = String.format("Message event subscription for businessKey %s named %s does not exist", order.get().getId(), "amyHome-"+ order.get().getId());
				throw new InvalidRequestException(Response.Status.NOT_FOUND, errorMessage);
			}
			Execution messageExecution = runtimeService.createExecutionQuery().executionId(eventSubscription.getExecutionId()).singleResult();
			Map<String, Object> variables = new HashMap<>();
			variables.put("variableName1", choice.getHome());
			variables.put("variableName2", choice.getHotel());
			runtimeService.messageEventReceived(eventSubscription.getEventName(), messageExecution.getId(), variables);