Skip to content

Commit

Permalink
Use target address from link for response sending.
Browse files Browse the repository at this point in the history
Signed-off-by: pellmann <marc.pellmann@bosch-si.com>
  • Loading branch information
pellmann committed May 23, 2018
1 parent 7c09ddf commit cbece71
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ private Future<Optional<Long>> openCommandReceiverLink(final RoutingContext ctx,
// send answer to caller via sender link
final Future<CommandResponseSender> responseSender = createCommandResponseSender(tenant, deviceId, replyId);
responseSender.map(commandResponseSender ->
commandResponseSender.sendCommandResponse(tenant, deviceId, replyId, getCorrelationIdFromMessage(commandMessage),
commandResponseSender.sendCommandResponse(getCorrelationIdFromMessage(commandMessage),
null, null, HttpURLConnection.HTTP_OK)
).map(protonDeliveryFuture -> {
LOG.debug("Command acknowledged to sender.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public interface CommandResponseSender extends MessageSender {
/**
* Sends a response message to a command back to the business application.
*
* @param tenantId The tenant that the command response will be send for and the device belongs to.
* @param deviceId The device that sends the command.
* @param replyId The reply id as the unique postfix of the replyTo address.
* @param correlationId The correlation id of the command.
* @param payload The payload or {@code null}.
* @param properties The properties or {@code null}.
Expand All @@ -26,9 +23,6 @@ public interface CommandResponseSender extends MessageSender {
* @throws NullPointerException if any of tenantId, deviceId, replyId or correlationId is {@code null}.
*/
Future<ProtonDelivery> sendCommandResponse(
String tenantId,
String deviceId,
String replyId,
String correlationId,
Buffer payload,
Map<String, Object> properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,26 @@ static final String getTargetAddress(final String tenantId, final String deviceI
* {@inheritDoc}
*/
public Future<ProtonDelivery> sendCommandResponse(
final String tenantId,
final String deviceId,
final String replyId,
final String correlationId,
final Buffer payload,
final Map<String, Object> properties,
final int status) {
LOG.debug("send back a command response [tenant: {}, device: {}, replyId: {}, correlationId: {}, status: {}]",
tenantId, deviceId, replyId, correlationId, status);
return sendAndWaitForOutcome(
createResponseMessage(tenantId, deviceId, replyId, correlationId, payload, properties, status));
LOG.debug("send back a command response [correlationId: {}, status: {}]", correlationId, status);
return sendAndWaitForOutcome(createResponseMessage(targetAddress, correlationId, payload, properties, status));
}

private static Message createResponseMessage(
final String tenantId,
final String deviceId,
final String replyId,
final String targetAddress,
final String correlationId,
final Buffer payload,
final Map<String, Object> properties,
final int status) {

Objects.requireNonNull(tenantId);
Objects.requireNonNull(deviceId);
Objects.requireNonNull(replyId);
Objects.requireNonNull(targetAddress);
Objects.requireNonNull(correlationId);
final Message msg = ProtonHelper.message();
msg.setCorrelationId(correlationId);
msg.setAddress(CommandResponseSenderImpl.getTargetAddress(tenantId, deviceId, replyId));
msg.setAddress(targetAddress);
if (payload != null) {
msg.setBody(new Data(new Binary(payload.getBytes())));
}
Expand Down

0 comments on commit cbece71

Please sign in to comment.