Hopefully your manager will be supportive if this ever happens in the workplace. You have the right to be respected so make sure you tell them straight away if you're being mistreated.
Working in retail basically my approach is to calmly say something along the lines of "I'm sorry but I won't serve you until you change your behaviour/treat me with respect' etc etc. Then if the person continues to be rude I'll go get the manager/most senior person rostered on and get their help dealing with the customer. Usually they'll tell the person to change their behaviour or else they'll be asked to leave the store.
If a customer is rude to me about something that is the company's fault and not mine I tell them that they're welcome to take their concerns further but I'm only acting based on directions from my manager as an employee and I don't have much jurisdiction.
Dealing with it afterwards is really important. I think the biggest thing is to speak to someone at work about it and debrief. Make sure you don't take it personally because most of the time it's directed at the company/store not you, despite the fact they're saying the mean stuff to you (obviously racism and stuff excepted - that's a very personal attack). And leave it at work, really. Over time you'll grow a thick skin and stuff won't affect you as much. You just have to compartmentalise, accept that not everyone is nice and friendly, and keep going with your day. It sucks that someone has treated you poorly, but you have to not think about it too much and don't give that person a second thought - if they've treated you poorly, they're really not worth your time (this is the biggest thing to remember for me).
If you're concerned, I'd recommend speaking to more experienced members of staff and your manager. They might not give you all this info initially (there's only so much you can talk to a new person about before you absolutely overwhelm them) but if you ask questions, you'll find out and I think most people should be happy to give you advice.
Hope this helps a bit and makes some sense!