当前位置: 首页>>代码示例>>Java>>正文


Java Header类代码示例

本文整理汇总了Java中org.springframework.messaging.handler.annotation.Header的典型用法代码示例。如果您正苦于以下问题:Java Header类的具体用法?Java Header怎么用?Java Header使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Header类属于org.springframework.messaging.handler.annotation包,在下文中一共展示了Header类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: objectMessage

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@RabbitListener(queues = "seqQueue")
public void objectMessage(@Payload UserDTO msg, @Header("my-header") String my_header, Message message) {
    System.out.println("message user:" + msg.getName());
    String myHeader =(String) message.getMessageProperties().getHeaders().get("my-header");

    logger.info("Here is my header:" + myHeader );
    logger.info("my header from annotation:" +my_header);
    try{
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(msg);
        logger.info("here is the message recived: " + json);
    }
    catch (JsonProcessingException exc){
        logger.info("exceptions ",exc);
    }

}
 
开发者ID:capesonlee,项目名称:tangtang-spring-cloud,代码行数:18,代码来源:AmqpReciver.java

示例2: sendInstructions

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
public void sendInstructions(@Header("HANDLER") String handler, List<ActionRequest> actionRequests,
    List<ActionCancel> actionCancels) {
  ActionInstruction instruction = new ActionInstruction();

  if (actionRequests != null) {
    ActionRequests requests = new ActionRequests();
    requests.getActionRequests().addAll(actionRequests);
    instruction.setActionRequests(requests);
  }

  if (actionCancels != null) {
    ActionCancels cancels = new ActionCancels();
    cancels.getActionCancels().addAll(actionCancels);
    instruction.setActionCancels(cancels);
  }

  String routingKey = String.format("%s%s%s", ACTION, handler, BINDING);
  rabbitTemplate.convertAndSend(routingKey, instruction);
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:20,代码来源:InstructionPublisherImpl.java

示例3: recieveMessageSp

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
/**
 * Handle the incoming Message from Queue with the property
 * (hawkbit.device.simulator.amqp.receiverConnectorQueueFromSp).
 *
 * @param message
 *            the incoming message
 * @param type
 *            the action type
 * @param thingId
 *            the thing id in message header
 * @param tenant
 *            the device belongs to
 */
@RabbitListener(queues = "${hawkbit.device.simulator.amqp.receiverConnectorQueueFromSp}")
public void recieveMessageSp(final Message message, @Header(MessageHeaderKey.TYPE) final String type,
        @Header(name = MessageHeaderKey.THING_ID, required = false) final String thingId,
        @Header(MessageHeaderKey.TENANT) final String tenant) {
    final MessageType messageType = MessageType.valueOf(type);

    if (MessageType.EVENT.equals(messageType)) {
        checkContentTypeJson(message);
        handleEventMessage(message, thingId);
        return;
    }

    if (MessageType.THING_DELETED.equals(messageType)) {
        checkContentTypeJson(message);
        repository.remove(tenant, thingId);
        return;
    }

    if (MessageType.PING_RESPONSE.equals(messageType)) {
        final String correlationId = new String(message.getMessageProperties().getCorrelationId(),
                StandardCharsets.UTF_8);
        if (!openPings.remove(correlationId)) {
            LOGGER.error("Unknown PING_RESPONSE received for correlationId: {}.", correlationId);
        }

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Got ping response from tenant {} with correlationId {} with timestamp {}", tenant,
                    correlationId, new String(message.getBody(), StandardCharsets.UTF_8));
        }

        return;
    }

    LOGGER.info("No valid message type property.");
}
 
开发者ID:eclipse,项目名称:hawkbit-examples,代码行数:49,代码来源:DmfReceiverService.java

示例4: sendMessageToAllUsers

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
/**
 * Send the given message to all users after checking the authorization of the user.
 * @param message The message to be sent.
 * @param accessToken The oauth2 accessToken of the user.
 * @return the message to the topic
 * @throws Exception Thrown if not authorized for instance.
 */
@MessageMapping("/user-messages")
@SendTo("/topic/user-messages")
public MessageDto sendMessageToAllUsers(MessageDto message, 
    @Header("access_token") String accessToken) throws Exception {
  OAuth2AccessToken oauth2accessToken = tokenStore.readAccessToken(accessToken);
  if (oauth2accessToken != null) {
    OAuth2Authentication authentication = tokenStore.readAuthentication(oauth2accessToken);
    if (authentication != null && authentication.getAuthorities().contains(
        new SimpleGrantedAuthority("ROLE_ADMIN"))) {
      message.setSender(authentication.getUserAuthentication().getName());
      log.debug("Sending message from {} to all users", message.getSender()); 
      return message;        
    }
  }
  log.error("Unauthorized message from {} with content: {}", 
      message.getSender(), message.getText());
  throw new SessionAuthenticationException("No valid access token found!");
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:26,代码来源:UserMessagesController.java

示例5: mix

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@WampCallListener(value = "messageMethod/{id}")
public String mix(String param1, CallMessage message, int param2,
		WampSession wampSession, @Headers Map<String, Object> headers,
		@Header(value = "WAMP_MESSAGE_TYPE") WampMessageType wampMessageType,
		float param3, @DestinationVariable("id") int id, String param4) {

	assertThat(param1).isEqualTo("param1");
	assertThat(message).isNotNull();
	assertThat(message.getDestination()).isEqualTo("messageMethod/23");
	assertThat(param2).isEqualTo(2);
	assertThat(wampSession).isNotNull();
	assertThat(headers).hasSize(5);
	assertThat(wampMessageType).isEqualTo(WampMessageType.CALL);
	assertThat(param3).isEqualTo(3.3f);
	assertThat(id).isEqualTo(23);
	assertThat(param4).isEqualTo("param4");

	return "mix";
}
 
开发者ID:ralscha,项目名称:wampspring,代码行数:20,代码来源:CallParameterTestService.java

示例6: receiveMessage

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@SqsListener(QUEUE_NAME)
private void receiveMessage(MessageToProcess message, @Header("ApproximateFirstReceiveTimestamp") String approximateFirstReceiveTimestamp) {
    LOG.debug("Received SQS message {}", message);

    try {
        this.sqsSendingTextWebSocketHandler.broadcastToSessions(new DataWithTimestamp<>(message, approximateFirstReceiveTimestamp));
    } catch (IOException e) {
        LOG.error("Was not able to push the message to the client.", e);
    }
}
 
开发者ID:spring-cloud-samples,项目名称:aws-refapp,代码行数:11,代码来源:SqsController.java

示例7: onSubscribe

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@SubscribeMapping("/queue/output")
public GameOutput onSubscribe(Principal principal,
                              @Header("breadcrumb") String breadcrumb,
                              @Header("simpSessionId") String simpSessionId) {
    Session session = getSessionFromPrincipal(principal);
    Map<String, String> sessionMap = session.getAttribute(breadcrumb);
    Entity entity = entityRepository.findOne(sessionMap.get("entity"));

    entity.setStompUsername(principal.getName());
    entity.setStompSessionId(simpSessionId);
    entity = entityRepository.save(entity);

    GameOutput output = new GameOutput();

    output.append("[black]  ___                            _   __  __ _   _ ___  ".replace(" ", "&nbsp;"));
    output.append("[dwhite] | __|_ __  ___ _ _ __ _ ___ _ _| |_|  \\/  | | | |   \\ ".replace(" ", "&nbsp;"));
    output.append("[dwhite] | _|| '  \\/ -_) '_/ _` / -_) ' \\  _| |\\/| | |_| | |) |".replace(" ", "&nbsp;"));
    output.append("[white] |___|_|_|_\\___|_| \\__, \\___|_||_\\__|_|  |_|\\___/|___/ ".replace(" ", "&nbsp;"));
    output.append("[white]                   |___/                               ".replace(" ", "&nbsp;"));
    output.append("[white]Copyright &copy; 2016-2017 Peter Keeler.");
    output.append("[dwhite]EmergentMUD is licensed under the <a class=\"green\" target=\"_blank\" " +
            "href=\"http://www.gnu.org/licenses/agpl-3.0.en.html\">GNU Affero General Public License</a>.");
    output.append("[dwhite]EmergentMUD offers no warranties or guarantees. Play at your own risk.");
    output.append("[red]EmergentMUD is in early stages of development. Reboots and database wipes may occur without warning!");
    output.append("[dwhite]EmergentMUD is <a class=\"green\" target=\"_blank\" " +
            "href=\"https://github.com/scionaltera/emergentmud\">free, open source software</a> that " +
            "[white]you [dwhite]can contribute to, modify and distribute as you wish.");
    output.append("[dwhite]EmergentMUD server status:");
    output.append("[dwhite]&nbsp;&nbsp;Version: [white]v" + applicationVersion);
    output.append("[dwhite]&nbsp;&nbsp;Up since: [white]" + new DateTime(applicationBootDate));
    output.append(String.format("[yellow]Welcome to the world, %s!", entity.getName()));
    output.append("");

    Command command = (Command)applicationContext.getBean("lookCommand");
    command.execute(output, entity, "look", new String[0], "");

    promptBuilder.appendPrompt(output);

    return output;
}
 
开发者ID:scionaltera,项目名称:emergentmud,代码行数:41,代码来源:WebSocketResource.java

示例8: mix

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@WampProcedure(name = "mix")
public String mix(String param1, CallMessage message, int param2,
		@Headers Map<String, Object> headers,
		@Header(value = "WAMP_MESSAGE_CODE") long code, float param3, String param4) {

	assertThat(param1).isEqualTo("param1");
	assertThat(message).isNotNull();
	assertThat(param2).isEqualTo(2);
	assertThat(headers).hasSize(3);
	assertThat(code).isEqualTo(CallMessage.CODE);
	assertThat(param3).isEqualTo(3.3f);
	assertThat(param4).isEqualTo("param4");

	return "mix";
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:16,代码来源:CallParameterTestService.java

示例9: handleMessage

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@SuppressWarnings("unused")
private void handleMessage(
		@Header String param1,
		@Header(name = "name", defaultValue = "bar") String param2,
		@Header(name = "name", defaultValue = "#{systemProperties.systemProperty}") String param3,
		String param4,
		@Header("nativeHeaders.param1") String nativeHeaderParam1) {
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:HeaderMethodArgumentResolverTests.java

示例10: receivedQueueMsg

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@JmsListener(destination = QUEUE)
public void receivedQueueMsg(String txt, @Header(value = DBCHECK,required = false, defaultValue = "false") boolean dbCheck ) {
    synchronized (receivedQueue) {
        if( dbCheck ) {
            tx.execute(status -> {
                TestObj testObj = entityManager.find(TestObj.class, Integer.parseInt(txt));
                assertNotNull(testObj);
                return null;
            });
        }
        logger.info("Received queue : " + txt);
        receivedQueue.add(txt);
    }
}
 
开发者ID:Kloudtek,项目名称:ktspring,代码行数:15,代码来源:TestHelper.java

示例11: sendMessage

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@Override
@Publisher(channel = "sftpOutbound")
public byte[] sendMessage(@Header(FileHeaders.REMOTE_FILE) String filename,
    @Header(ACTION_LIST) List<String> actionIds,
    ByteArrayOutputStream stream) {
  return stream.toByteArray();
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:8,代码来源:SftpServicePublisherImpl.java

示例12: receive

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@KafkaListener(id = "batch-listener", topics = "${kafka.topic.batch}")
public void receive(List<String> data,
    @Header(KafkaHeaders.RECEIVED_PARTITION_ID) List<Integer> partitions,
    @Header(KafkaHeaders.OFFSET) List<Long> offsets) {
  LOGGER.info("start of batch receive");
  for (int i = 0; i < data.size(); i++) {
    LOGGER.info("received message='{}' with partition-offset='{}'", data.get(i),
        partitions.get(i) + "-" + offsets.get(i));
    // handle message

    latch.countDown();
  }
  LOGGER.info("end of batch receive");
}
 
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:15,代码来源:Receiver.java

示例13: handleWithReply

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@ServiceActivator
public List<SimpleRequest> handleWithReply(SimpleRequest request,
                                           @Header(value = "RESPONSE_TYPE") String responseType) {
	log.info("handleWithReply(): request=" + request.getSomeMessageExtra() + " RESPONSE_TYPE=" + responseType);
	request.setSomeMessageExtra("StubHandler_");
	final List<SimpleRequest> list = Lists.newArrayList();
	list.add(request);
	return list;
}
 
开发者ID:EldadDor,项目名称:Spring-Integration-ShowCase,代码行数:10,代码来源:SimpleStub.java

示例14: getIngredientForAmount

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@ServiceActivator(inputChannel = "inventoryStoreRequestExChannel", outputChannel = "inventoryStoreResponseChannel")
public Message<Ingredient> getIngredientForAmount(@Header(value = "Quantity") Integer quantity, Message<Ingredient> message) {
	final Ingredient ingredient = message.getPayload();
	final String key = ingredient.getClass().getSimpleName();
	if (inventoryRepositoryMap.containsKey(key)) { // if in inventory
		final Pair<? super Class<Ingredient>, Long> ingredientRepo = inventoryRepositoryMap.get(key);
		if (ingredientRepo.getRight() > 0 && ingredientRepo.getRight() >= quantity) { // if there some amount in inventory
			((MutablePair) ingredientRepo).setRight(ingredientRepo.getRight() - quantity); // setting the amount of taking the required
			ingredient.setMass(quantity);
			return MessageBuilder.withPayload(ingredient).build();
		}
	}
	return null;
}
 
开发者ID:EldadDor,项目名称:Spring-Integration-ShowCase,代码行数:15,代码来源:InventoryStoreServiceActivator.java

示例15: receive

import org.springframework.messaging.handler.annotation.Header; //导入依赖的package包/类
@StreamListener(Processor.INPUT)
public void receive(@Payload StreamListenerTestUtils.FooPojo fooPojo,
		@Headers Map<String, Object> headers,
		@Header(MessageHeaders.CONTENT_TYPE) String contentType) {
	this.receivedArguments.add(fooPojo);
	this.receivedArguments.add(headers);
	this.receivedArguments.add(contentType);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:9,代码来源:StreamListenerAnnotatedMethodArgumentsTests.java


注:本文中的org.springframework.messaging.handler.annotation.Header类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。