Saturday 15 May 2010

java - Send email and update database -



java - Send email and update database -

i read items database using repositoryitemreader convert them mimemessages using itemprocessor , send them using mimemessageitemwriter

all of works great.

but when project email has been sent, update database project , set sentmail date, next time job run, doesn't resend emails have gone out.

where should database change?

in reader? happens if smtp doesn't repond, whole chunk rolled back? in processor, or composite processor? in writer? that's no because it's mimemessage , don't have projectid more.

or should utilize listener?

you should have service level class wraps whole processing :

read database (and maintain id) create mimemessage send message update database

that way can update database if send message (ok smtp server, starting point story ...)

edit: in context of spring-batch, service level spring-batch itself

in context of spring-batch, reader part fine, , should utilize mimemessageitemwriter send message. must able follow steps described above. imho simple solution extend mimemessage in class :

class messageandid extends mimemessage { private int databaseid; // or whatever id private boolean senderror; public messageandid(mimemessage source, int databaseid) { super(source); this.databaseid = databaseid; senderror = false; } }

your itemprocessor should convert input messageandid, , author should composite writer, first calling mimemessageitemwriter custom error handler set senderrorto true in handle method, next calling itemwriter update database knowing database id , status of each message.

java spring spring-batch

No comments:

Post a Comment