Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java springjmsactivemq_Java_Jms_Activemq_Spring Jms - Fatal编程技术网

Java springjmsactivemq

Java springjmsactivemq,java,jms,activemq,spring-jms,Java,Jms,Activemq,Spring Jms,我使用activemq和SpringJMS。我有个问题 这是我的电子邮件发送者 @Service @PropertySource("classpath:/properties/dev/application.properties") public class EmailSenderImpl implements EmailSender { private static final Logger LOGGER = LoggerFactory.getLogger(EmailSenderImp

我使用activemq和SpringJMS。我有个问题

这是我的电子邮件发送者

@Service
@PropertySource("classpath:/properties/dev/application.properties")
public class EmailSenderImpl implements EmailSender {
    private static final Logger LOGGER = LoggerFactory.getLogger(EmailSenderImpl.class);

    @Autowired
    private JmsTemplate jmsTemplate;

    @Autowired
    private Environment env;

    @Override
    public void sendEmail(final Users user, EmailCauses emailCause) {
        LOGGER.debug("Sending email to user with id {} with cause {}", user.getId(), emailCause);

        //Retrieve User profile which defined with lazy fetch type.
        //It prevents org.hibernate.LazyInitializationException in jms message receiver method
        user.getUserProfile();

        jmsTemplate.send(env.getProperty(emailCause.getEmailQueueName()),
                new MessageCreator () {

                    @Override
                    public Message createMessage(Session session) throws JMSException {
                        return session.createObjectMessage(user);
                    }
                }
        );  
    } 
这是我的电子邮件处理程序

@Service
public class EmailHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger(EmailHandler.class);

    private JavaMailSender mailSender;
    private VelocityEngine velocityEngine;
    private MessageSource messageSource;


    @Autowired
    public EmailHandler (JavaMailSender mailSender, VelocityEngine velocityEngine, MessageSource messageSource) {

        this.mailSender = mailSender;
        this.velocityEngine = velocityEngine;
        this.messageSource = messageSource;
    }


    //TODO - refactor method, add reserve server
    @Transactional
    public void processEmailNotifications (Users user) throws MessagingException, UnsupportedEncodingException {
        LOGGER.debug("Preparing to send greeting email to user {}", user);

        UserProfiles userProfile = user.getUserProfile();

        Map <String, Object> model = new HashMap <> ();
        model.put("name", userProfile.getName());
        model.put("patronymic", userProfile.getPatronymic());
        model.put("token", UriUtils.encode(user.getConfirmationToken(), "UTF8"));

        String email = user.getUserProfile().getEmail();
        sendEmail(email, "email.wellcome.subject", model, "wellcome_email.vm");

    }
     private void sendEmail (String emailTo, String subjectMessage, Map<String, Object> model, String templateName) {
        LOGGER.debug("Sending email to {} with subject message {}", emailTo, subjectMessage);

        try {

            MimeMessage message = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper (message, true, "UTF-8");

            helper.setTo(emailTo);
            helper.setSubject(messageSource.getMessage(subjectMessage, null, Locale.getDefault()));

            String emailText = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, "UTF-8", model);
            helper.setText(emailText, true);

            mailSender.send(message);
            LOGGER.info("Email to address {} with subject {} was sent successfully", emailTo, subjectMessage);

        } catch (MessagingException me) {
            LOGGER.error("Email to address {} was not sent", emailTo, me);

        }

    }
@服务
公共类电子邮件处理程序{
私有静态最终记录器Logger=LoggerFactory.getLogger(EmailHandler.class);
私有JavaMailSender;
私人VelocityEngine VelocityEngine;
私有消息源;
@自动连线
公共电子邮件处理程序(JavaMailSender-mailSender、VelocityEngine-VelocityEngine、MessageSource-MessageSource){
this.mailssender=mailssender;
this.velocityEngine=velocityEngine;
this.messageSource=messageSource;
}
//TODO-重构方法,添加保留服务器
@交易的
public void processEmailNotifications(用户)引发MessaginException、UnsupportedEncodingException{
debug(“准备向用户{}发送问候电子邮件”,用户);
UserProfiles userProfile=user.getUserProfile();
Map model=newhashmap();
model.put(“name”,userProfile.getName());
model.put(“patronymic”,userProfile.getPatronymic());
model.put(“token”,UriUtils.encode(user.getConfirmationToken(),“UTF8”);
字符串email=user.getUserProfile().getEmail();
sendEmail(电子邮件,“email.wellcome.subject”,模型,“wellcome_email.vm”);
}
私有void sendmail(字符串emailTo、字符串subjectMessage、映射模型、字符串templateName){
debug(“向{}发送带有主题消息{}”、emailTo、subjectMessage的电子邮件);
试一试{
MimeMessage message=mailssender.createMimeMessage();
mimessagehelper=新的mimessagehelper(消息,true,“UTF-8”);
helper.setTo(emailTo);
setSubject(messageSource.getMessage(subjectMessage,null,Locale.getDefault());
字符串emailText=VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,templateName,“UTF-8”,型号);
setText(emailText,true);
发送(消息);
LOGGER.info(“向地址{}发送的主题为{}的电子邮件已成功发送”,emailTo,subjectMessage);
}捕获(消息例外我){
LOGGER.error(“未发送到地址{}的电子邮件”,emailTo,me);
}
}
我的堆栈跟踪中有以下日志。我不明白为什么它不工作

o、 s.jms.core.JmsTemplate-在jms会话上执行回调: ActiveMQSession {id=id:igor-Aspire-5820TG-33061-1474030841626-1:7:1,start=false} 2016-09-16 16:02:40.871-[http-bio-8080-exec-6][DEBUG] o、 s.jms.core.JmsTemplate-发送创建的消息: ActiveMQTextMessage{commandId=0,responseRequired=false, messageId=null,originalDestination=null,originalTransactionId= null,producerId=null,destination=null,transactionId=null, 过期时间=0,时间戳=0,到达时间=0,中断时间=0, BrokerRoutTime=0,correlationId=null,replyTo=null,持久= false,type=null,priority=0,groupID=null,groupSequence=0, targetConsumerId=null,compressed=false,userID=null,content= null,marshalledProperties=null,dataStructure=null, redeliveryCounter=0,size=0,properties=null,readOnlyProperties =false,readOnlyBody=false,droppable=false,text=xDDD}


您是否可以发布其他日志和JmsTemplate设置配置,因为会话未在您的日志和生产者、messageid和目的地上启动…信息为空?您是否可以发布其他日志和JmsTemplate设置配置,因为会话未在您的日志和生产者、messageid和目的地上启动…信息为空